I like my code to be completely indented / paranthesized with explicit variable names (they may take longer, but they are much easier to debug), so I would do the following (but changing "myTextFile" and "myStringList" to more reasonable names, for example , "employeeListTextFile")
QFile myTextFile; QStringList myStringList; if (!myTextFile.open(QIODevice::ReadOnly)) { QMessageBox::information(0, "Error opening file", myTextFile.errorString()); } else { while(!myTextFile.atEnd()) { myStringList.append(myTextFile.readLine()); } myTextFile.close(); }
source share