Most likely, the file is simply not located. Check whether the file is open before working with it:
QFile file("file.txt"); if(file.open(QIODevice::ReadOnly)) { QTextStream str(&file); QString s = str.readAll(); qDebug() << s; file.close(); }
And you can even easier:
QFile file("file.txt"); if(file.open(QIODevice::ReadOnly)) { QString s = file.readAll(); qDebug() << s; file.close(); }
As I wrote - I noticed, you readAll() calls for qDebug() on the stream object, although you should output s . This may also give an empty output (the documentation does not mention what readAll() does with the internal state of the stream)