Reputation: 2808
I need to read strings from foo.txt:
#include <QDebug>
#include <QFile>
#include <QStringList>
#include <QTextStream>
int main( int argc, char** argv )
{
QFile file("foo.txt");
if (!file.open(QIODevice::ReadOnly))
return 1;
QStringList stringList;
QTextStream textStream(&file);
textStream.readLine();
while (!textStream.atEnd())
stringList << textStream.readLine();
file.close();
qDebug() << stringList;
return 0;
}
file opened, but textStream always empty.
Upvotes: 0
Views: 344
Reputation: 13421
From your comment it would appear that the executable is simply not finding the file as they are in different locations. There are a variety of ways to solve this and it depends on what the final use case is meant to be. Here are some ways you can solve the issue:
For testing either of the first two options are quick and easy but you will probably want something better than that if you intend to take things further.
Upvotes: 1