Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QDataStream not writing
hi may you please assist the following code does not work it only ceate and empty file.dat file.
am using Qt 5.15.2 on windows 10 home 64 bit.
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
QFile file("file.dat"); file.open(QIODevice::WriteOnly); QDataStream out(&file); // we will serialize the data into the file out << QString("the answer is "); // serialize a string out << (qint32)42; // serialize an integer QFile file2("file.dat"); file2.open(QIODevice::ReadOnly); QDataStream in(&file2); // read the data serialized from the file QString str; qint32 b; in >> str >> b; // extract "the answer is" and 42 qDebug()<< str << b; return a.exec();
You should close the file before trying to open it again.
This post is deleted!
thank you it worked
nothing written on bytearray can you please assist
QDataStream out(&file); // we will serialize the data into the file
out >> data;
You are not checking that the file opening is successful. The path being relative, it's likely failing.
@tinashe Why do you think a png file contains QDateStream encoded data?
I think its my misunderstanding the use if this class I was just looking for a class which can make my life easier in sending picture data using Qudp or QTCP . Thanks