How to get executable name in Qt

后端 未结 3 576
星月不相逢
星月不相逢 2021-02-06 22:02

I run a Qt application, what I want to know is this running binary file name.

3条回答
  •  离开以前
    2021-02-06 22:31

    I must (partially) disagree with the other comments that it is not a Qt question: There is a Qt method QCoreApplication::applicationFilePath() which gives the directory+filename of the executable.

    On Linux this will try to use /proc, and on Windows perhaps GetModuleFileName(). According to the docs it will fall back to argv[0].

    You could then use QFileInfo to split it into an executable name and a directory.

    QFileInfo(QCoreApplication::applicationFilePath()).fileName()
    

提交回复
热议问题