sda*_*dfd 5 c++ qt qmake qt-creator
我正在尝试在可执行文件的当前位置打开一个xml文件
QString path = QDir::currentPath();
path.append("/acc.xml");
QFile file(path);
if(!file.open(QIODevice::ReadOnly))
{
insertItem("IO ERR");
}
Run Code Online (Sandbox Code Playgroud)
当我从Qt创建者运行它时,一切正常.currentPath()返回可执行文件夹的路径
当我去project-build-desktop/文件夹并尝试运行它手动currentPath()返回/home/user/Documents
编辑
也试过相同的结果:
Qt::current().path();
Qt::current().absolutePath();
Run Code Online (Sandbox Code Playgroud)
Joh*_*nny 10
尝试使用QCoreApplication :: applicationDirPath()而不是QDir :: currentPath().
有关详细信息,请参阅http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath
| 归档时间: |
|
| 查看次数: |
26974 次 |
| 最近记录: |