How can I read a text file line by line in Qt?
I'm looking for the Qt equivalent to:
std::ifstream infile; std::string line; while (std::getline(infile, line)) { ... }
Use this code:
QFile inputFile(fileName); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); while (!in.atEnd()) { QString line = in.readLine(); ... } inputFile.close(); }
2.1m questions
2.1m answers
60 comments
57.0k users