当前位置: 首页>>代码示例>>C++>>正文


C++ QDataStream类代码示例

本文整理汇总了C++中QDataStream的典型用法代码示例。如果您正苦于以下问题:C++ QDataStream类的具体用法?C++ QDataStream怎么用?C++ QDataStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QDataStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readString

QString readString(QDataStream &stream)
{
	QString res = "";
	while(true || !stream.atEnd())
	{
		char data[2];
		stream.readRawData(data, 2);
		
		if (data[0] == 0x00)
			break;
	
		if(data[0] != 0x00)
            res += QChar::fromLatin1(data[0]);
        /*
         * короче не знает он что такое этот фром аски, пробовал инклюды разные и доставлял либы, не помогло
         * sea-kg: беда... метод в ку5 морально устарел... может попробовать res += QChar::fromLatin1(data[0]) ???
         * или res += QChar(QLatin1Char(data[0]).unicode());
         * http://qt-project.org/doc/qt-5.0/qtcore/qchar.html
         * Static Public Method
         * QChar 	fromAscii(char c) (deprecated)
         * Converts the ASCII character c to it's equivalent QChar. This is mainly useful for non-internationalized software.
         * An alternative is to use QLatin1Char.
         */
    }
	return res;
}
开发者ID:forensictool,项目名称:coex,代码行数:26,代码来源:evtReader.cpp

示例2: writeVector

void writeVector(QDataStream& out, char ch, QVector<T> vec) {
    // Minimum number of bytes to consider compressing
    const int ATTEMPT_COMPRESSION_THRESHOLD_BYTES = 2000;

    out.device()->write(&ch, 1);
    out << (int32_t)vec.length();

    auto data { QByteArray::fromRawData((const char*)vec.constData(), vec.length() * sizeof(T)) };

    if (data.size() >= ATTEMPT_COMPRESSION_THRESHOLD_BYTES) {
        auto compressedDataWithLength { qCompress(data) };

        // qCompress packs a length uint32 at the beginning of the buffer, but the FBX format
        // does not expect it. This removes it.
        auto compressedData = QByteArray::fromRawData(
            compressedDataWithLength.constData() + sizeof(uint32_t), compressedDataWithLength.size() - sizeof(uint32_t));

        if (compressedData.size() < data.size()) {
            out << FBX_PROPERTY_COMPRESSED_FLAG;
            out << (int32_t)compressedData.size();
            out.writeRawData(compressedData.constData(), compressedData.size());
            return;
        }
    }

    out << FBX_PROPERTY_UNCOMPRESSED_FLAG;
    out << (int32_t)0;
    out.writeRawData(data.constData(), data.size());
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:29,代码来源:FBXWriter.cpp

示例3: files

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
        }
}
开发者ID:stramel,项目名称:drasterblaster,代码行数:28,代码来源:advanced.cpp

示例4: out

//отправление данных по всем кораблям
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);
}
开发者ID:SimpleName,项目名称:practice,代码行数:60,代码来源:myserver.cpp

示例5: msg

// ------------------------------------------------------------------------ //
void RunModule::resetASICs()
{
    //if(dbg())
        msg()("Resetting VMMs...","RunModule::resetASICs");

    bool ok;
    QByteArray datagram;

    // send trigger mode to VMMAPP port
    int send_to_port = config().commSettings().vmmapp_port;

    // headers
    QString cmd, cmdType, cmdLength, msbCounter;
    cmd = "AA";
    cmdType = "AA";
    cmdLength = "FFFF";
    msbCounter = "0x80000000"; 

    for(const auto& ip : socket().ipList()) {
        datagram.clear();
        QDataStream out (&datagram, QIODevice::WriteOnly);
        out.device()->seek(0); //rewind

        socket().updateCommandCounter();

        ///////////////////////////
        // header info
        ///////////////////////////
        out << (quint32)(socket().commandCounter() + msbCounter.toUInt(&ok,16)) //[0,3]
            << (quint16) 0 //[4,5] 
            << (quint16) config().getHDMIChannelMap() //[6,7]
            << (quint8) cmd.toUInt(&ok,16) //[8]
            << (quint8) cmdType.toUInt(&ok,16) //[9]
            << (quint16) cmdLength.toUInt(&ok,16); //[10,11]

        ///////////////////////////
        // reset
        ///////////////////////////
        out << (quint32) 0 //[12,15]
            << (quint32) 128 //[16,19]
            << (quint32) 2; //[20,23]

        socket().SendDatagram(datagram, ip, send_to_port, "fec",
                                                "RunModule::resetASICs");
        bool readOK = true;
        readOK = socket().waitForReadyRead("fec");
        if(readOK) {
            if(dbg()) msg()("Processing replies...","RunModule::resetASICs");
            socket().processReply("fec", ip);
        } else {
            msg()("Timeout while waiting for replies from VMM",
                    "RunModule::resetASICs",true);
            socket().closeAndDisconnect("fec","RunModule::resetASICs");
            exit(1);
        }
    } // ip

    socket().closeAndDisconnect("fec", "RunModule::resetASICs");
}
开发者ID:dantrim,项目名称:VMMReadout,代码行数:60,代码来源:run_module.cpp

示例6: waitForAvailableBytes

static bool waitForAvailableBytes(QDataStream &stream, quint32 count)
{
    while (stream.device()->bytesAvailable() < count) {
        if (!stream.device()->waitForReadyRead(SOCKET_DELAY_MS)) {
            return false;
        }
    }
    return true;
}
开发者ID:khertan,项目名称:qt-components,代码行数:9,代码来源:mthemedaemonprotocol.cpp

示例7: stream

bool PwDatabaseV3::readDatabase(const QByteArray& dbBytes) {
    QDataStream stream (dbBytes);
    stream.setByteOrder(QDataStream::LittleEndian);

    PwHeaderV3::ErrorCode headerErrCode = header.read(stream);
    if (headerErrCode != PwHeaderV3::SUCCESS) {
        LOG("%s: %d", PwHeaderV3::getErrorMessage(headerErrCode).toUtf8().constData(), headerErrCode);
        emit dbLoadError(PwHeaderV3::getErrorMessage(headerErrCode), headerErrCode);
        return false;
    }

    /* Calculate the encryption key */
    setPhaseProgressBounds(UNLOCK_PROGRESS_KEY_TRANSFORM);
    PwDatabase::ErrorCode dbErr = transformKey(header.getMasterSeed(), header.getTransformSeed(),
            header.getTransformRounds(), combinedKey, masterKey);
    if (dbErr != PwDatabase::SUCCESS) {
        LOG("Cannot decrypt database - transformKey: %d", dbErr);
        emit dbLoadError(tr("Cannot decrypt database", "A generic error message"), dbErr);
        return false;
    }


    /* Decrypt data */
    setPhaseProgressBounds(UNLOCK_PROGRESS_DECRYPTION);
    int dataSize = dbBytes.size() - header.HEADER_SIZE;
    // DB header not needed for decryption
    QByteArray dbBytesWithoutHeader = dbBytes.right(dataSize);
    QByteArray decryptedData(dataSize, 0);
    ErrorCode err = decryptData(dbBytesWithoutHeader, decryptedData);
    Util::safeClear(dbBytesWithoutHeader);
    if (err != SUCCESS) {
        if (err == DECRYPTED_PADDING_ERROR || err == DECRYPTED_CHECKSUM_MISMATCH) {
            LOG("Cannot decrypt database - decryptData: %d", err);
            emit invalidPasswordOrKey();
        } else {
            // err == CANNOT_DECRYPT_DB
            // err == CONTENT_HASHING_ERROR
            // err == something else
            LOG("Cannot decrypt database - decryptData: %d", err);
            emit dbLoadError(tr("Cannot decrypt database", "An error message"), err);
        }
        return false;
    }

    /* Reading and parsing data*/
    setPhaseProgressBounds(UNLOCK_PROGRESS_PARSE_DATA);
    QDataStream decryptedDataStream(decryptedData);
    decryptedDataStream.setByteOrder(QDataStream::LittleEndian);
    err = readContent(decryptedDataStream);
    Util::safeClear(decryptedData);
    if (err != SUCCESS) {
        emit dbLoadError(tr("Cannot parse database", "An error message. Parsing refers to the analysis/understanding of file content (do not confuse with reading it)."), err);
        return false;
    }

    return true;
}
开发者ID:piotrkubisa,项目名称:keepassb,代码行数:57,代码来源:PwDatabaseV3.cpp

示例8: readQInt16asLittleEndian

qint16 readQInt16asLittleEndian(QDataStream &stream)
{
	QDataStream::ByteOrder bo = stream.byteOrder();
	stream.setByteOrder(QDataStream::LittleEndian);
	quint16 res;
	stream >> res;
	stream.setByteOrder(bo);
	return res;
}
开发者ID:forensictool,项目名称:coex,代码行数:9,代码来源:reader.cpp

示例9: config

// ------------------------------------------------------------------------ //
void RunModule::s6clocks(int cktk, int ckbc, int ckbc_skew)
{
    if(dbg()) msg()("Setting S6 clocks...","RunModule::s6clocks");

    bool ok;
    QByteArray datagram;

    // send call to s6 port
    int send_to_port = config().commSettings().s6_port;

    QString cmd, msbCounter;
    cmd = "AAAAFFFF";
    msbCounter = "0x80000000";

    for(const auto& ip : socket().ipList()) {
        datagram.clear();
        QDataStream out (&datagram, QIODevice::WriteOnly);
        out.device()->seek(0); //rewind

        socket().updateCommandCounter();

        ////////////////////////////
        // header
        ////////////////////////////
        out << (quint32)(socket().commandCounter() + msbCounter.toUInt(&ok,16)) //[0,3]
            << (quint32) config().getHDMIChannelMap() //[4,7]
            << (quint32) cmd.toUInt(&ok,16); //[8,11]

        ////////////////////////////
        // command
        ////////////////////////////
        out << (quint32) 0 //[12,15]
            << (quint32) 6 //[16,19]
            << (quint32) (cktk*16) //[20,23]
            << (quint32) 7 //[24,27]
            << (quint32) ( ckbc + (ckbc_skew*16) ); //[28,31]

        socket().SendDatagram(datagram, ip, send_to_port, "fec",
                                            "RunModule::s6clocks");

        bool readOK = true;
        readOK = socket().waitForReadyRead("fec");
        if(readOK) {
            if(dbg()) msg()("Processing replies...","RunModule::s6clocks");
            socket().processReply("fec",ip);
        } else {
            msg()("Timout while waiting for replies from VMM",
                    "RunModule::s6clocks", true);
            socket().closeAndDisconnect("fec","RunModule::s6clocks");
            exit(1);
        }
    } // ip

    socket().closeAndDisconnect("fec","RunModule::s6clocks");

}
开发者ID:dantrim,项目名称:VMMReadout,代码行数:57,代码来源:run_module.cpp

示例10: rle_decode

static qint32 rle_decode(QDataStream & abr, char *buffer, qint32 height)
{
    qint32 n;
    char ptmp;
    char ch;
    int i, j, c;
    short *cscanline_len;
    char *data = buffer;

    // read compressed size foreach scanline
    cscanline_len = new short[ height ];
    for (i = 0; i < height; i++) {
        // short
        abr >> cscanline_len[i];
    }

    // unpack each scanline data
    for (i = 0; i < height; i++) {
        for (j = 0; j < cscanline_len[i];) {
            // char
            if (!abr.device()->getChar(&ptmp)) {
                break;
            }
            n = ptmp;

            j++;
            if (n >= 128)     // force sign
                n -= 256;
            if (n < 0) {      // copy the following char -n + 1 times
                if (n == -128)  // it's a nop
                    continue;
                n = -n + 1;
                // char
                if (!abr.device()->getChar(&ch)) {
                    break;
                }

                j++;
                for (c = 0; c < n; c++, data++) {
                    *data = ch;
                }
            }
            else {
                // read the following n + 1 chars (no compr)
                for (c = 0; c < n + 1; c++, j++, data++) {
                    // char
                    if (!abr.device()->getChar(data))  {
                        break;
                    }
                }
            }
        }
    }
    delete [] cscanline_len;
    return 0;
}
开发者ID:AninaRJ,项目名称:krita,代码行数:56,代码来源:kis_abr_brush_collection.cpp

示例11: readBinaryArray

QVariant readBinaryArray(QDataStream& in, int& position) {
    quint32 arrayLength;
    quint32 encoding;
    quint32 compressedLength;

    in >> arrayLength;
    in >> encoding;
    in >> compressedLength;
    position += sizeof(quint32) * 3;

    QVector<T> values;
    if ((int)QSysInfo::ByteOrder == (int)in.byteOrder()) {
        values.resize(arrayLength);
        QByteArray arrayData;
        if (encoding == FBX_PROPERTY_COMPRESSED_FLAG) {
            // preface encoded data with uncompressed length
            QByteArray compressed(sizeof(quint32) + compressedLength, 0);
            *((quint32*)compressed.data()) = qToBigEndian<quint32>(arrayLength * sizeof(T));
            in.readRawData(compressed.data() + sizeof(quint32), compressedLength);
            position += compressedLength;
            arrayData = qUncompress(compressed);
            if (arrayData.isEmpty() ||
                (unsigned int)arrayData.size() != (sizeof(T) * arrayLength)) { // answers empty byte array if corrupt
                throw QString("corrupt fbx file");
            }
        } else {
            arrayData.resize(sizeof(T) * arrayLength);
            position += sizeof(T) * arrayLength;
            in.readRawData(arrayData.data(), arrayData.size());
        }

        if (arrayData.size() > 0) {
            memcpy(&values[0], arrayData.constData(), arrayData.size());
        }
    } else {
        values.reserve(arrayLength);
        if (encoding == FBX_PROPERTY_COMPRESSED_FLAG) {
            // preface encoded data with uncompressed length
            QByteArray compressed(sizeof(quint32) + compressedLength, 0);
            *((quint32*)compressed.data()) = qToBigEndian<quint32>(arrayLength * sizeof(T));
            in.readRawData(compressed.data() + sizeof(quint32), compressedLength);
            position += compressedLength;
            QByteArray uncompressed = qUncompress(compressed);
            if (uncompressed.isEmpty()) { // answers empty byte array if corrupt
                throw QString("corrupt fbx file");
            }
            QDataStream uncompressedIn(uncompressed);
            uncompressedIn.setByteOrder(QDataStream::LittleEndian);
            uncompressedIn.setVersion(QDataStream::Qt_4_5); // for single/double precision switch
            for (quint32 i = 0; i < arrayLength; i++) {
                T value;
                uncompressedIn >> value;
                values.append(value);
            }
        } else {
            for (quint32 i = 0; i < arrayLength; i++) {
开发者ID:ZappoMan,项目名称:hifi,代码行数:56,代码来源:FBXReader_Node.cpp

示例12:

/** Erases loaded data from memory */
PwHeaderV3::ErrorCode PwHeaderV3::write(QDataStream& outStream) {
    outStream << SIGNATURE_1 << SIGNATURE_2 << flags << DB_VERSION;
    outStream.writeRawData(masterSeed.constData(), masterSeed.size());
    outStream.writeRawData(initialVector.constData(), initialVector.size());
    outStream << groupCount << entryCount;
    outStream.writeRawData(contentHash.constData(), contentHash.size());
    outStream.writeRawData(transformSeed.constData(), transformSeed.size());
    outStream << transformRounds;
    return SUCCESS;
}
开发者ID:piotrkubisa,项目名称:keepassb,代码行数:11,代码来源:PwDatabaseV3.cpp

示例13: writeSizeToCache

bool IconCacheCreator::writeSizeToCache(QDataStream &out, const QList<int> &sizes) {
    for (int i = 0; i < sizes.size(); i++) {
        //out << sizes.at(i);
        DPRINT("size: %d", out.device()->size());
        out.writeRawData((const char *)&(sizes.at(i)), sizeof(int));
        DPRINT("size: %d", out.device()->size());
    }

    return true;
}
开发者ID:chris-magic,项目名称:studycode,代码行数:10,代码来源:IconCacheCreator.cpp

示例14: readUtf8

QString readUtf8(QDataStream& stream){
    int size;
    stream.readRawData((char*)&size,sizeof(int));
    if (size==0)
        return "";
    char* utf8 = new char[size];
    stream.readRawData(utf8,size);
    QString value = QString::fromUtf8(utf8,size);
    delete [] utf8;
    return value;
}
开发者ID:vasilenkomike,项目名称:TrackYourTime,代码行数:11,代码来源:cexternaltrackers.cpp

示例15: 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);
}
开发者ID:AlanForeverAi,项目名称:Exams,代码行数:55,代码来源:server.cpp


注:本文中的QDataStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。