2013-09-27 112 views
9

我有一個適用於Mac和Windows的基於Qt的應用程序。當用戶安裝軟件時,它還會安裝一個包含一堆HTML文檔頁面的文件夾。如何找到程序的安裝位置,以便當用戶嘗試從應用程序中打開幫助時,它們被帶到index.html如何找到Qt應用程序的安裝目錄?

我的程序安裝在Windows和Mac的正常位置。在Mac上,我的程序安裝到/Users/username/Applications/MyProgram,其中MyProgram是包含「MyProgram.app」和「Doc」文件夾的文件夾。

#ifdef Q_OS_MACX 
    docPath = executablePath + "/Doc/index.html"; 
#elif Q_OS_WIN 
    docPath = executablePath + "/Doc/index.html"; 
#endif 

    QDesktopServices::openUrl(QUrl::fromLocalFile(docPath)); 

那麼,我的最終問題是,executablePath應該是什麼?此外,這假定用戶可以在除默認位置之外的其他地方安裝該程序,或者該程序可以從快捷方式啓動。

+0

可能重複[如何在Qt中獲得可執行文件名](http://stackoverflow.com/questions/4515602/how-to-get-executable-name-in -qt) – syam

+0

是不是QCoreApplication :: applicationDirPath(http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#applicationDirPath)正是你想要的嗎? – Zlatomir

回答

18

你應該使用:

QString QCoreApplication::applicationDirPath() [static] 
+0

參考http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath – maxschlepzig

相關問題