0
我需要打开配置文件。配置文件位置是exe文件所在的目录。基本上,我怎么能得到这个位置?如何确定使用Qt的可执行文件的目录?
我试图使用QDir,但是当前代码返回错误,当文件没有打开。
QString cfg_name = QDir::currentPath() + "config.cfg";
QFile File(cfg_name);
if (File.open(QIODevice::ReadOnly))
{
QTextStream in(&File);
int elementId;
while (!in.atEnd())
{
QString line = in.readLine();
filename[elementId] = line;
elementId++;
}
}
else
{
QMessageBox msgBox;
msgBox.setText("Can't open configuration file!");
msgBox.exec();
}
File.close();
它仍然返回我的消息框,什么时候能” t打开文件。 –
我在代码中发现错误,对不起。 'QString cfg_name = QDir :: currentPath()+“/config.cfg”;' –
@ЦунскийНикита谢谢,纠正了我的答案。 – jotik