Qt-读取文件内容
1. 利用QFile和QTextStream
vector Dialog::ReadFile(const QString &fileName)
{
vector contents;
QFile file(fileName);
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream textStream(&file);
while (!textStream.atEnd())
{
contents.push_back(textStream.readLine());
}
}
return contents;
}