2013-04-24 39 views
0

我在linux中開發了一個GUI應用程序。 當前,應用程序的版本信息顯示在GUI內。
現在,我的客戶想他應該能夠檢查通過輸入應用程序的版本,下面的命令:如何爲linux應用程序添加版本信息

[shell]: appName --version 

我所做如下:

int main(int argc, char *argv[]) 
{ 

    /* Initialize Qt Application */ 
    QApplication simulatorGUI(argc, argv); 

    QStringList argList = simulatorGUI.arguments(); 

    if((argList.count() == 2) && (argList[1].toStdString() == "--version")) 
    { 
     cout << "App Simulator V2.3" << endl; 
    } 

    simulatorGUI.setStyle(new QCleanlooksStyle); 
     appSimulator simulatorInstance; 
     simulatorInstance.show(); 
     return simulatorGUI.exec(); 
}  

使用此代碼我能夠檢查我的應用程序的版本信息爲:

[shell]: ./appSimulator --version  
App Simulator V2.3  

並運行該應用程序,我使用以下命令:

[shell]: ./appSimulator  

我的疑問是:
1.這是執行的正確方法?
2.是否有更好的實現方法?我能做到這樣的:

[shell]: appSimulator --version 

,而不是

[shell]: ./appSimulator --version 

謝謝。

+0

不要忘記實施'appsSiulator --help'程序參數。 – 2013-04-24 06:03:39

回答

1

這應該足夠了。 ./取決於你的路徑,所以如果程序可以在你的路徑中找到,你將不需要它。

+0

謝謝你的回覆。還有一個疑問:我怎麼能有一個從任何地方被調用的應用程序,而無需使用./ ??我相信它與垃圾箱中的添加有關。 – Jay 2013-04-24 03:56:28

+0

它與你可以更新的'PATH'環境變量有關,例如在'bash'的'.login'或'.profile'或'.bashrc'初始化文件中 – 2013-04-24 06:03:09

相關問題