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; }
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()); }
void Message::Deserialize (const QByteArray& data) { QDataStream str (data); str.setVersion (QDataStream::Qt_4_8); quint8 version = 0; str >> version; if (version != 1) throw std::runtime_error (qPrintable ("Failed to deserialize Message: unknown version " + QString::number (version))); str >> FolderID_ >> MessageID_ >> Folders_ >> Size_ >> Date_ >> Recipients_ >> Subject_ >> IsRead_ >> Body_ >> HTMLBody_ >> InReplyTo_ >> References_ >> Addresses_ >> Attachments_; QByteArray headerBA; str >> headerBA; if (!headerBA.isEmpty ()) VmimeHeader_ = std::make_shared<LazyVmimeHeader> (headerBA); else VmimeHeader_.reset (); }
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 } }
//отправление данных по всем кораблям 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); }
// ------------------------------------------------------------------------ // 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"); }
static bool waitForAvailableBytes(QDataStream &stream, quint32 count) { while (stream.device()->bytesAvailable() < count) { if (!stream.device()->waitForReadyRead(SOCKET_DELAY_MS)) { return false; } } return true; }
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; }
qint16 readQInt16asLittleEndian(QDataStream &stream) { QDataStream::ByteOrder bo = stream.byteOrder(); stream.setByteOrder(QDataStream::LittleEndian); quint16 res; stream >> res; stream.setByteOrder(bo); return res; }
// ------------------------------------------------------------------------ // 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"); }
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; }
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++) {
/** 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; }
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; }
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; }
/*数据读取函数*/ 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); }
// ------------------------------------------------------------------------ // void RunModule::checkLinkStatus() { if(dbg()) msg()("Checking link status...","RunModule::checkLinkStatus"); bool ok; QByteArray datagram; // send call to vmmapp port int send_to_port = config().commSettings().vmmapp_port; // header QString cmd = "BBAAFFFF"; QString 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) 16; //[16,19] socket().SendDatagram(datagram, ip, send_to_port, "fec", "RunModule::checkLinkStatus"); bool readOK = true; readOK = socket().waitForReadyRead("fec"); if(readOK) { emit checkLinks(); //if(dbg()) msg()("Processing replies...","RunModule::checkLinkStatus"); //socket().processReply("fec", ip); } else { msg()("Timeout while waiting for replies from VMM", "RunModule::checkLinkStatus", true); socket().closeAndDisconnect("fec", "RunModule::checkLinkStatus"); exit(1); } } // ip socket().closeAndDisconnect("fec", "RunModule::checkLinkStatus"); }
void Frame::write(QDataStream &stream) { QByteArray lenbuf; stream << (quint8)_header; if(_data.size() == 0) { stream << (quint8)0; return; } encodeLength(lenbuf, _data.size()); stream.writeRawData(lenbuf.data(), lenbuf.size()); stream.writeRawData(_data.data(), _data.size()); }
void LYTTextBox::readFromDataStream(QDataStream &in) { qint64 saveStartPos = in.device()->pos(); LYTPane::readFromDataStream(in); // the lengths are stored in bytes (not characters) and count the // zero terminator, and strings are UTF-16 (I think) so we need // to take it off here in >> (quint16&)bufferLength; bufferLength >>= 1; bufferLength--; quint16 stringLength; in >> (quint16&)stringLength; stringLength >>= 1; stringLength--; // read the material and font names quint16 materialNum, fontNum; in >> (quint16&)materialNum; in >> (quint16&)fontNum; materialName = m_layout.materials.getNameOfIndex(materialNum); fontName = m_layout.m_fontRefs.at(fontNum); in >> (quint8&)alignment; in >> (quint8&)alignmentOverride; in.skipRawData(2); // padding quint32 stringOffset; in >> (quint32&)stringOffset; ReadRGBA8Color(colour1, in); ReadRGBA8Color(colour2, in); in >> (float&)fontSizeX; in >> (float&)fontSizeY; in >> (float&)charSpace; in >> (float&)lineSpace; // read the textbox contents // subtract 8 to account for BinaryBlockHeader or whatever it's called in.device()->seek(saveStartPos + stringOffset - 8); ushort *rawText = new ushort[stringLength]; for (int i = 0; i < stringLength; i++) in >> (quint16&)rawText[i]; text.setUtf16(rawText, stringLength); delete[] rawText; }
bool huancun::readcfg(){ qDebug()<<"huancun::readcfg"; QFile file; QString cfg=dirpath+"/cfg"; file.setFileName(cfg); if(file.open(QIODevice::ReadOnly)) { QDataStream in; in.setDevice(&file); in>>all>>name>>goon>>playurl>>urls>>playrf>>U_A; return true; }
bool Titres::DB_Charger(void) { QFile file(SAVENAME); QDataStream out; if ( file.open(QIODevice::ReadOnly) ) { out.setDevice(&file); out >> T_List; file.close(); return true; }
void SessionManager::read() { QFile f(_sessionsPath); QDataStream in; QVariant tmp; Session *session(0); // Opening the saving file if (!f.open(QIODevice::ReadOnly)) return; in.setDevice(&f); // Reading of all sessions while (!in.atEnd()) { session = new Session(); // Retrieving of the access token in >> tmp; session->setAccessToken(tmp.toString()); tmp.clear(); // Retrieving of the client token in >> tmp; session->setClientToken(tmp.toString()); tmp.clear(); // Retrieving of the player's uuid in >> tmp; session->setUuid(tmp.toString()); tmp.clear(); // Retrieving of the player's username in >> tmp; session->setName(tmp.toString()); tmp.clear(); // Retrieving of the player's legacy in >> tmp; session->setLegacy(tmp.toBool()); tmp.clear(); } f.close(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QVariantMap variantMap; QString string = "testString"; variantMap["test"] = string; QVariantMap nestedMap; QString nestedString = "nestedString"; nestedMap["nested"] = nestedString; variantMap["nestedTest"] = nestedMap; const int length = 256; unsigned char* buffer = new unsigned char[length]; for (int i = 0; i < length; i++) { buffer[i] = i; } QFile file("file.dat"); file.open(QIODevice::WriteOnly); QDataStream out(&file); out << variantMap; out.writeRawData(reinterpret_cast<const char *>(buffer), length); file.close(); file.open(QIODevice::ReadOnly); QDataStream in (&file); QVariantMap variantMapIn; in >> variantMapIn; in.readRawData(reinterpret_cast<char *>(buffer), length); qDebug() << variantMapIn["test"].toString(); qDebug() << variantMapIn["nestedTest"].toMap()["nested"].toString(); qDebug() << "buffer 23:" << static_cast<int>(buffer[23]); this->dumpObjectTree(); this->dumpObjectInfo(); delete[] buffer; }
void KMessageSocket::processNewData () { if (isRecursive) return; isRecursive = true; QDataStream str (mSocket); while (mSocket->bytesAvailable() > 0) { if (mAwaitingHeader) { // Header = magic number + packet length = 5 bytes if (mSocket->bytesAvailable() < 5) { isRecursive = false; return; } // Read the magic number first. If something unexpected is found, // start over again, ignoring the data that was read up to then. quint8 v; str >> v; if (v != 'M') { qCWarning(GAMES_PRIVATE_KGAME) << ": Received unexpected data, magic number wrong!"; continue; } str >> mNextBlockLength; mAwaitingHeader = false; } else { // Data not completely read => wait for more if (mSocket->bytesAvailable() < (qint64) mNextBlockLength) { isRecursive = false; return; } QByteArray msg (mNextBlockLength, 0); str.readRawData (msg.data(), mNextBlockLength); // send the received message emit received (msg); // Waiting for the header of the next message mAwaitingHeader = true; } }
bool FeatureConnector::readRing(QDataStream& stream, std::vector<Coordinate2d> &ring ) { quint32 numberOfCoords; if (stream.readRawData((char *)&numberOfCoords, 4) <= 0) return ERROR1(ERR_COULD_NOT_OPEN_READING_1,"data file"); vector<XYZ> pnts(numberOfCoords); stream.readRawData((char *)&pnts[0],numberOfCoords*3*8); ring.resize(numberOfCoords); for(quint32 i=0; i < numberOfCoords; ++i) { ring[i] = Coordinate2d(pnts[i].x, pnts[i].y); } return true; }
void KBuildMimeTypeFactory::save(QDataStream &str) { KSycocaFactory::save(str); str << (qint32) 0; const int endOfFactoryData = str.device()->pos(); // Update header (pass #3) saveHeader(str); // Seek to end. str.device()->seek(endOfFactoryData); }
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; }
void KBuildServiceTypeFactory::save(QDataStream &str) { KSycocaFactory::save(str); #if 0 // not needed since don't have any additional index anymore int endOfFactoryData = str.device()->pos(); // Update header (pass #3) saveHeader(str); // Seek to end. str.device()->seek(endOfFactoryData); #endif }
void ElogThread::addAttachment( QDataStream& stream, const QString& boundary, const QByteArray& byteArray, int iFileNumber, const QString& name ) { if (byteArray.count() > 0) { QString strStart = QString("Content-Disposition: form-data; name=\"attfile%1\"; filename=\"%2\"\r\n\r\n").arg(iFileNumber).arg(name); QString strEnd = QString("%1\r\n").arg(boundary); stream.writeRawBytes(strStart.ascii(), strStart.length()); stream.writeRawBytes(byteArray.data(), byteArray.count()); stream.writeRawBytes(strEnd.ascii(), strEnd.length()); } }
bool QPicture::play( QPainter *painter ) { if ( pictb.size() == 0 ) // nothing recorded return TRUE; pictb.open( IO_ReadOnly ); // open buffer device QDataStream s; s.setDevice( &pictb ); // attach data stream to buffer if ( !formatOk ) { // first time we read it char mf_id[4]; // picture header tag s.readRawBytes( mf_id, 4 ); // read actual tag if ( memcmp(mf_id, mfhdr_tag, 4) != 0 ) { // wrong header id #if defined(CHECK_RANGE) qWarning( "QPicture::play: Incorrect header" ); #endif pictb.close(); return FALSE; } int cs_start = sizeof(Q_UINT32); // pos of checksum word int data_start = cs_start + sizeof(Q_UINT16); Q_UINT16 cs,ccs; QByteArray buf = pictb.buffer(); // pointer to data s >> cs; // read checksum ccs = qChecksum( buf.data() + data_start, buf.size() - data_start ); if ( ccs != cs ) { #if defined(CHECK_STATE) qWarning( "QPicture::play: Invalid checksum %x, %x expected", ccs, cs ); #endif pictb.close(); return FALSE; } Q_UINT16 major, minor; s >> major >> minor; // read version number if ( major > mfhdr_maj ) { // new, incompatible version #if defined(CHECK_RANGE) qWarning( "QPicture::play: Incompatible version %d.%d", major, minor); #endif pictb.close(); return FALSE; } formatOk = TRUE; // picture seems to be ok formatMajor = major; formatMinor = minor; } else {