My QTextStream is empty when this code finishes:
QString line1 = "This is line one";
QString line2 = "This is line two";
QString line3 = "This is line three";
QString outputFilename = "temp.txt";
QFile outputFile(outputFilename);
outputFile.open(QIODevice::WriteOnly);
outputFile.open(QIODevice::ReadWrite); // This fixes the problem
QTextStream out1(&outputFile);
out1 << line1 << endl;
out1 << line2 << endl;
out1 << line3 << endl;
outputFile.flush();
QString temp = out1.readAll();
mainclipboard->setText(temp);
outputFile.close();
Here, the QString temp is empty. What have I missed?
Thanks to hyde for the answer.