qdatastream

Converting QImage to QByteArray using QDataStream

China☆狼群 提交于 2021-02-11 14:00:20
问题 Im trying to convert a QImage that maked from ScreenShot to a QByteArray for sending via QTCPSocket. when i convert QImage to QByteArray and before sending it i try to deserialize and show it on label it cant ! what's my mistake? thx for helping. QByteArray ImClientShooter::toQByteArray(QImage &img) { QByteArray temp; QDataStream data(&temp, QIODevice::ReadWrite); data « img; return temp; } QByteArray goOn{toQByteArray(sampleQImage)}; //sampleQImage is a QImage Object lbl->setPixmap(QPixmap:

Reading specific object in QDataStream and count number of objects stored

若如初见. 提交于 2020-03-05 00:31:04
问题 I am writting some objects in a binary file and I would like to read them back. To explain you what I am trying to do, I prepared a simple example with a class User that contains the QString name and QList name of childrens. Please see the code below. #include "QString" #include "QFile" #include "QDataStream" #include "qdebug.h" class User { protected: QString name; QList<QString> childrens; public: QString getName(){ return name;} QList<QString> getChildrens(){ return childrens;} void

Reading specific object in QDataStream and count number of objects stored

不问归期 提交于 2020-03-05 00:29:08
问题 I am writting some objects in a binary file and I would like to read them back. To explain you what I am trying to do, I prepared a simple example with a class User that contains the QString name and QList name of childrens. Please see the code below. #include "QString" #include "QFile" #include "QDataStream" #include "qdebug.h" class User { protected: QString name; QList<QString> childrens; public: QString getName(){ return name;} QList<QString> getChildrens(){ return childrens;} void

How to open a bin file in Python using QDataStream

℡╲_俬逩灬. 提交于 2020-01-11 10:34:24
问题 I've got a bin file that was encoded in an application that I need to get access to and convert to a csv file. I've been given the documentation, but am not sure how to access the contents of this file in Python. Here are some of the details about how the dataset was serialized Datasets.bin is a list of DataSet classes serialized using Qt's QDataStream serialization using version QDataStream::Qt_4_7. The format of the datasets.bin file is: quint32 Magic Number 0x46474247 quint32 Version 1

Save and load QList<Class*> to file

帅比萌擦擦* 提交于 2020-01-03 05:36:42
问题 I have a class ContactData and a class FriendList holding a QList and I overloaded the << / >> operators. contactdata.h class ContactData { //all public for testing public: ContactData(); QString m_name; QString m_description; bool m_online; }; QDataStream &operator<<(QDataStream& out, ContactData& contactData); QDataStream &operator>>(QDataStream& in, ContactData* contactData); contactdata.cpp QDataStream &operator<<(QDataStream &out, ContactData& contactData) { out << contactData.m_name;

QDataStream unable to serialize data

可紊 提交于 2019-12-25 04:10:53
问题 I am trying to follow the tutorial here and serialize Qt objects. Here is my code: QFile file("/Users/kaustav/Desktop/boo.dat"); if (!file.open(QIODevice::WriteOnly)) { qDebug() << "Cannot open file for writing: " << qPrintable(file.errorString()) << endl; //no error message gets printed return 0; } QDataStream out(&file); // we will serialize the data into the file out.setVersion(QDataStream::Qt_5_3); //adding this makes no difference out << QString("the answer is"); // serialize a string

How do I properly serialize and deserialize a QList class in QT using QDatastream?

眉间皱痕 提交于 2019-12-23 19:48:34
问题 I am trying to serialize a custom class Layer* and read it back using QDataStream. Now, Layer is an abstract class with virtual method which is inherited by different kinds of layers: RasterLayer , TextLayer , AdjustmentLayer etc. I have a QList<Layer*> layers which keeps track of all the layers, and any adjustments made to a layer are updated in the list. I need to serialize and deserialize the QList to its original state and restore the properties of the individual layers (of different

saving and loading vector<Mat> Qt & OpenCV

假装没事ソ 提交于 2019-12-11 14:04:07
问题 I'm working on face recognition in Qt & openCV using the FisherFaces recognizer which doesn't support updating so i have to save the faces database to retrain the recognizer after any changes. Here is my code for saving : save(const std::vector* MatVect){ QFile file("students_dataset.dat"); file.open(QIODevice::WriteOnly); QDataStream out(&file); QVector qimgvect; for (size_t i = 0; i < MatVect->size(); ++i) { cv::Mat matt = MatVect->at(i); QImage img((uchar*)matt.data, matt.cols, matt.rows,

Qt - QDataStream with overloaded operator<< for object pointer (Class*)

眉间皱痕 提交于 2019-12-11 06:04:04
问题 I am trying to read/write my custom classes using QDataStream. I have overridden the << and >> operators, which seem to work fine for normal objects. However, when I try to pass a pointer to my custom object, the overridden operators don't work properly. Here is the relevant data from card.h: #ifndef CARD_H #define CARD_H #include <QDataStream> #include <QImage> #include <QString> class Card { private: QString name; QImage image; QString type; int strength; int movement; int deployCost;

Append a QByteArray to QDataStream?

£可爱£侵袭症+ 提交于 2019-12-06 09:02:04
问题 I have to populate a QByteArray with different data. So I'm using the QDataStream . QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); qint8 dataHex= 0x04; qint8 dataChar = 'V'; stream << dataHex<< dataChar; qDebug() << buffer.toHex(); // "0456" This is what I want However, I would also like to append a QByteArray to the buffer . QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); qint8 dataHex= 0x04; qint8 dataChar = 'V'; QByteArray moreData = QByteArray: