1)按行读取
QString apppath = QApplication::applicationDirPath() + "/host.txt";
// qDebug()<<"apppath = "<<apppath;
QFile hostfile(apppath);
if (hostfile.exists()){
hostfile.open(QIODevice::ReadOnly);
QTextStream stream(&hostfile);
program.hostURL = stream.readLine();
program.basePath = stream.readLine();
program.htmlUrl = stream.readLine();
program.demensionUrl = stream.readLine();
// qDebug()<<"program.hostURL="<<program.hostURL;
// qDebug()<<"program.hostPort="<<program.hostPort;
hostfile.close();
}
2)写文件
QFile accountFile(QApplication::applicationDirPath() + "/account.txt");
accountFile.open(QIODevice::WriteOnly)
if (!accountFile.write(accountName.toStdString().c_str()))
{
//保存错误
}
accountFile.close();