在QT线面需要获取可执行文件坐在的路径,通常使用QT自带的函数:
QString exePath
= QCoreApplication
::applicationDirPath();
但是,在项目中调用这个函数没有起作用。
int main(int argc
, char *argv
[]) {
QString exePath
= QCoreApplication
::applicationDirPath();
QApplication
app(argc
, argv
);
......
}
原来是这个函数调用的位置不对,应该放在QApplication实例化之后,因为应为程序实例还没有实例化呢,所以获取不到当前程序对象所在的路径,修改一下就可以了。
int main(int argc
, char *argv
[]) {
QApplication
app(argc
, argv
);
QString exePath
= QCoreApplication
::applicationDirPath();
......
}
aaa