本文主要是介绍QT获取程序运行的路径,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在工程中需要使用程序运行时使用的路径问题
/* 获取文件生成的目录 */QString path = QCoreApplication::applicationDirPath();
解释如下:
QString QCoreApplication::applicationFilePath()
Returns the file path of the application executable.
For example, if you have installed Qt in the /usr/local/qt directory, and you run the regexp example, this function will return “/usr/local/qt/examples/tools/regexp/regexp”.
Warning: On Linux, this function will try to get the path from the /proc file system. If that fails, it assumes that argv[0] contains the absolute file name of the executable. The function also assumes that the current directory has not been changed by the application.
这篇关于QT获取程序运行的路径的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!