本文整理汇总了C++中QDataStream::setVersion方法的典型用法代码示例。如果您正苦于以下问题:C++ QDataStream::setVersion方法的具体用法?C++ QDataStream::setVersion怎么用?C++ QDataStream::setVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDataStream
的用法示例。
在下文中一共展示了QDataStream::setVersion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: chargerFichier
void AddressBook::chargerFichier() {
QString nomFichier = QFileDialog::getOpenFileName(this,
tr ("Charger depuis un fichier"),
"",
tr ("Carnet d'adresse (*.abk);;Tous les fichiers (*)"));
if (nomFichier.isEmpty())
return;
else {
QFile fichier (nomFichier);
if (!fichier.open(QIODevice::ReadOnly)) {
QMessageBox::information(this,
tr ("Erreur de chargement"),
fichier.errorString());
return;
}
QDataStream in (&fichier);
in.setVersion(QDataStream::Qt_4_7);
listeContacts.empty();
in >> listeContacts;
if (listeContacts.isEmpty()) {
QMessageBox::information (this ,
tr ("Pas de contacts"),
tr ("Aucun contact à importer dans le fichier"));
} else {
QMap<QString , QString>::iterator i = listeContacts.begin();
nomLineEdit->setText(i.key());
adresseTextEdit->setText(i.value());
}
}
updateInterface(NavigationMode);
}
示例2: onReadyRead
void NetWorkClient::onReadyRead()
{
QDataStream in ( this );
in.setVersion(QDataStream::Qt_4_0); // Для совместимости с серверной частью
while (this->bytesAvailable() > 0){
if (packetSize == -1) {
//Определим количество байт доступных для чтения min >= 8 byte
if( (PACKET_SIZE) this->bytesAvailable() < (PACKET_SIZE) sizeof(packetSize) ){
return;
}
in >> packetSize;//Читаем размер пакета
}
//Проверим что в сокет пришел весь пакет а не его огрызки
if (this->bytesAvailable() < packetSize){
return;
}
//Сбросим размер пакета, для обработки следующего
packetSize = -1;
// Прочтем тип сообщения
int m_Type;
in >> m_Type;
//Прочтем само сообщение
QByteArray data;
in >> data;
Message message( this );
message.setType((MessageType) m_Type);
message.setMessageData( data );
// Отправка сообщения
emit reciveMessage( message );
}
}
示例3: qt_init
// Called before first plot after a set term command.
void qt_init()
{
// Start the QtGnuplotApplication if not already started
if (qt_initialized)
return;
// Fork the GUI if necessary
int argc = 0;
pid_t pid = 0;
pid = fork();
if (pid < 0)
fprintf(stderr, "Forking error\n");
else if (pid == 0) // Child: start the GUI
{
signal(SIGINT, SIG_IGN); // Do not listen to SIGINT signals anymore
QtGnuplotApplication application(argc, (char**)( NULL));
application.exec();
exit(0);
}
// Parent: create a QApplication without event loop for QObject's that need it
QApplication* application = new QApplication(argc, (char**)( NULL));
// Init state variables
qt_localServerName = "qtgnuplot" + QString::number(pid);
qt_out.setVersion(QDataStream::Qt_4_4);
qt_initialized = true;
GP_ATEXIT(qt_atexit);
// The creation of a QApplication mangled our locale settings
#ifdef HAVE_LOCALE_H
setlocale(LC_NUMERIC, "C");
setlocale(LC_TIME, current_locale);
#endif
}
示例4: onIpcData
void ScProcess::onIpcData()
{
mIpcData.append(mIpcSocket->readAll());
while (mIpcData.size()) {
QBuffer receivedData ( &mIpcData );
receivedData.open ( QIODevice::ReadOnly );
QDataStream in ( &receivedData );
in.setVersion ( QDataStream::Qt_4_6 );
QString selector, message;
in >> selector;
if ( in.status() != QDataStream::Ok )
return;
in >> message;
if ( in.status() != QDataStream::Ok )
return;
mIpcData.remove ( 0, receivedData.pos() );
onResponse(selector, message);
emit response(selector, message);
}
}
示例5: out
ContestantConnection::ContestantConnection ( ServerNetwork* sn, QTcpSocket* socket ) : QObject ( sn ) {
m_snet = sn;
m_answer_capable = true;
m_hdr = NULL;
m_authenticated = false;
m_socket = socket;
connect ( m_socket, SIGNAL ( error ( QAbstractSocket::SocketError ) ),
this, SLOT ( error ( QAbstractSocket::SocketError ) ) );
connect ( m_socket, SIGNAL ( readyRead() ), this, SLOT ( ready() ) );
connect ( m_socket, SIGNAL ( disconnected() ), this, SLOT ( disconnected() ) );
// reply to client of the now established connection
QByteArray block;
QDataStream out ( &block, QIODevice::WriteOnly );
out.setVersion ( QDataStream::Qt_4_5 );
// construct the header
p_header hdr;
hdr.length = sizeof ( ushort );
hdr.command = NET_CONNECTION_RESULT;
out.writeRawData ( ( const char* ) &hdr, sizeof ( p_header ) );
out << ( ushort ) true;
m_socket->write ( block );
m_socket->flush();
m_qnum = m_snet->getQNumber();
m_qtime = m_snet->getQTime();
m_qstatus = m_snet->getQStatus();
}
示例6: ready
void TempConnection::ready()
{
QDataStream in ( m_socket );
in.setVersion ( QDataStream::Qt_4_5 );
if ( m_hdr == NULL ) {
if ( m_socket->bytesAvailable() < ( int ) sizeof ( p_header ) ) {
return;
}
m_hdr = new p_header;
in.readRawData ( ( char* ) m_hdr, sizeof ( p_header ) );
//check the packet
if ( strcmp ( ( const char* ) m_hdr->ident.data, "CERB" ) != 0 ) {
// bad packet, do something here
return;
}
//check the version
if ( !is_proto_current ( m_hdr->ver ) ) {
// the version is not the same, do something here
}
}
if ( m_socket->bytesAvailable() < m_hdr->length ) {
return;
}
if ( m_hdr->command == NET_INITIATE_CONNECTION ) {
uchar client_type;
in >> client_type;
emit newClient ( this, static_cast<CLIENT_ID> ( client_type ) );
} else {
示例7: saveParams
void Advanced::saveParams()
{
QFileDialog dialogRaster;
dialogRaster.setAcceptMode(QFileDialog::AcceptSave);
dialogRaster.setFileMode(QFileDialog::AnyFile);
dialogRaster.setDirectory(QDir::toNativeSeparators(QCoreApplication::applicationDirPath()));
dialogRaster.setFilter(QDir::Files);
dialogRaster.setWindowTitle("Save Projection Parameters");
dialogRaster.setNameFilter("Config files (*.config)");
dialogRaster.exec();
QString filename = dialogRaster.selectedFiles().first();
if (filename.isEmpty())
return;
else
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
return;
}
QDataStream out (&file);
out.setVersion(12);
//out << ;//Write DATA here
}
}
示例8: save
bool Serialization::save(std::multiset<Event *, Cmp_event_day> &events)
{
//Save file to disk
QFile file("events.txt");
if(!file.open(QIODevice::WriteOnly))
{
qDebug() << "Could not open file";
return false;
}
//create output stream
QDataStream out (&file);
//set output version
out.setVersion(QDataStream::Qt_4_8);
//iteration
std::multiset<Event *>::iterator it;
for ( it=events.begin() ; it != events.end(); it++ )
out << **it;
//Finito! flush the stream to the file and close
file.flush();
file.close();
return true;
}
示例9: sendAllData
//отправление данных по всем кораблям
void MyServer::sendAllData(){
//deleteShipButton->setEnabled(false);
QByteArray block;
QDataStream out (&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_5);
out << quint16(0) << logNumbersOfRemovedShips.size(); //количество удаленных кораблей
for(int k = 0; k < logNumbersOfRemovedShips.size(); k++){ //номер лога удаленного корабля
out << logNumbersOfRemovedShips.at(k); //
}
logNumbersOfRemovedShips.clear();
out << shipCounter; //количество существующих на сервере кораблей
//для всех кораблей
for(int i=0; i < shipCounter; i++){
generateData(shipList.at(i)); //генерируем новые данные
out << shipList.at(i)->id
<< shipList.at(i)->startX
<< shipList.at(i)->startY
<< shipList.at(i)->courseAngle
<< shipList.at(i)->speed
<< shipList.at(i)->viewAngle
<< shipList.at(i)->viewLength
<< shipList.at(i)->pathLength
<< shipList.at(i)->time;
QTextEdit *te = (QTextEdit*)txtStack->widget(i); //получение указателя на лог текущего корабля
te->append(QString("Id: %1").arg(shipList.at(i)->id+1));//вывод сгенерированной информации в лог
if(shipList.at(i)->isNew){
te->append(QString("Start X: %1\nStart Y: %2")
.arg(shipList.at(i)->startX)
.arg(shipList.at(i)->startY));
}
te->append(QString("Course angle: %1 deg\nSpeed: %2\nView angle: %3 deg\nViewLength: %4\nPath length: %5 m\nTime: %6 sec\n")
.arg(shipList.at(i)->courseAngle)
.arg(shipList.at(i)->speed).arg(shipList.at(i)->viewAngle)
.arg(shipList.at(i)->viewLength).arg(shipList.at(i)->pathLength).arg(shipList.at(i)->time/1000.0f));
shipList.at(i)->isNew=0;
}
out.device()->seek(0); //переход в начало блока
out<<quint16(block.size()-sizeof(quint16)); //размер блока данных
if(isClientConnected) socket->write(block); //посылка клиенту, если он подключен
block.clear(); //очистка используемого блока
if(!deleteShipButton->isEnabled()&& shipCounter>0) deleteShipButton->setEnabled(true);
}
示例10: readData
/*数据读取函数*/
void ClientSocket::readData()
{
QDataStream in;
in.setDevice(this);
in.setVersion(QDataStream::Qt_4_7);
QVariant v;
AllAnswers allAnswers;
Student student;
/*如果还没有块大小信息则尝试去读取*/
if(_totalBytes == 0)
{
/*如果缓存区中可读数据的大小小于块大小信息的大小则返回*/
if(this->bytesAvailable()<sizeof(qint32))
return;
/*写入块大小信息*/
in >> _totalBytes;
}
/*如果缓存区可读信息的大小小于块大小则返回*/
if(this->bytesAvailable()<_totalBytes)
return;
/*反之则说明完整的数据块已经到达缓存区,可以开始读取*/
/*写入信息类型*/
in >> _messageType;
/*根据信息类型写入信息内容*/
switch(_messageType)
{
case MSG_NEWCONNECT:
in >> student;
v.setValue(student);
break;
case MSG_LOGIN:
in >> student;
student.setSockDescriptor(this->socketDescriptor());
v.setValue(student);
break;
case MSG_GETPAPER:
in >> student;
v.setValue(student);
break;
case MSG_ANSWER:
in >> allAnswers;
v.setValue(allAnswers);
break;
case MSG_ANSWERSINGLE:
in >> allAnswers;
v.setValue(allAnswers);
break;
}
/*将块大小信息重置为0,准备接收下一个数据块*/
_totalBytes = 0;
/*发送信息到达信号*/
emit this->messageArrive(this->socketDescriptor(),_messageType,v);
}
示例11: saveFeatures
void saveFeatures(QDataStream &outstream, const QString &extractorName,
const QStringList &extractorArgs, const int &extractorSize,
const QVector<LabelledData> &data)
{
outstream.setVersion(QDataStream::Qt_4_6);
outstream.setByteOrder(QDataStream::BigEndian);
int size = sizeof(nnreal);
outstream << size;
outstream << extractorName;
outstream << extractorArgs;
outstream << extractorSize;
outstream << data;
}
示例12: savePaperSetRelationFile
//保存各试卷关系信息
int CardDoc::savePaperSetRelationFile(int courseIndex, QString fileName)
{
QList<QString> setId;
QList<int> dpi;
QList<int> pageCount;
QList<QString> pageId;
QList<bool> isPositive;
vector<PaperSet>::iterator iter = m_course.at(courseIndex).set.begin();
for (; iter != m_course.at(courseIndex).set.end(); ++iter)
{
setId.push_back(iter->setId);
dpi.push_back(iter->dpi);
pageCount.push_back(iter->page.size());
vector<PaperPage>::iterator iter2 = iter->page.begin();
for (; iter2 != iter->page.end(); ++iter2)
{
pageId.push_back(iter2->pageId);
isPositive.push_back(iter2->isPositive);
}
}
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
{
return 0;
}
QDataStream data;
data.setDevice(&file);
data.setVersion(QDataStream::Qt_4_8);
//输出试卷关系信息
data << quint32(PAPERSET_MAGIC_NUM) << quint32(VERSION)
<< m_acType << m_course.at(courseIndex).courseName
<< m_course.at(courseIndex).set.size() << setId << dpi
<< pageCount << pageId << isPositive;
if (file.isOpen())
{
file.close();
}
return 1;
}
示例13: ensureSerializesCorrectly
void ensureSerializesCorrectly(const QPicture &picture, QDataStream::Version version)
{
QDataStream stream;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
stream.setDevice(&buffer);
stream.setVersion(version);
stream << picture;
buffer.close();
buffer.open(QIODevice::ReadOnly);
QPicture readpicture;
stream >> readpicture;
QVERIFY2(memcmp(picture.data(), readpicture.data(), picture.size()) == 0,
qPrintable(QString::fromLatin1("Picture data does not compare equal for QDataStream version %1").arg(version)));
}
示例14: Login
bool PackageReader::Login()
{
QDataStream socketStream;
socketStream.setVersion(QDataStream::Qt_4_8);
socketStream.setDevice(s);
struct User *user;
int nameLen,passwdLen;
QString name,passwd;
socketStream>>nameLen;
if(nameLen<0||nameLen>MAX_STR_LEN)
{
socketStream<<FAULT;
return 0;
}
name.resize(nameLen);
socketStream>>name;
socketStream>>passwdLen;
if(passwdLen<0||passwdLen>MAX_STR_LEN)
{
socketStream<<FAULT;
return 0;
}
passwd.resize(passwdLen);
socketStream>>passwd;
qDebug()<<"user name"<<name<<"passwd:"<<passwd;
/*bala
*bala
*bala
*/
user = new struct User;
user->name=name;
user->add=s->peerAddress();
user->online=1;
user->port=s->peerPort();
qDebug()<<user->name;
if(-1==l->Insert(user))
{
delete user;
socketStream<<FAULT;
return 0;
}
socketStream<<SUCCEED;
return 1;
}
示例15: commandReceived
void Analyzer::commandReceived(const QByteArray &commandline)
{
QDataStream in (commandline);
in.setVersion(QDataStream::Qt_4_7);
uchar command;
in >> command;
if (channelCommands.contains(command)) {
qint32 chanid;
in >> chanid;
/* Because we're giving a pointer to a locally declared instance, this connection must
be a DIRECT connection and never go in Queued mode. If you want queued mode, find another
way to transfer the data */
emit channelCommandReceived(command, chanid, &in);
return;
}