I have the code:
QTextStream out(mFileHandle);
out << (QTime::currentTime().toString(Qt::LocalDate) + " - ").toAscii();
out << "Something another";
std::cout << "Data: \n";
std::cout << out.string();
out.flush();
It writes to file but after ‘Data:’ I get ‘0’, why? How to send data to both streams?
It looks to me like you constructed your QTextStream out from a file handle. This means that it is going to write to that file.
The .string() method in QTextStream is only to access the QString used to construct it. In this case, it is zero, since you didn’t use a string to construct it.
If you want to access the all the text that has been written to the QTextstream, you probably want to pass it a QByteArray as the constructor argument. This will make it write output to that QByteArray, rather than out to a file. Then, you can access the contents written to the stream through the QByteArray.