开发者

How to get executable name in Qt

I run a Qt appli开发者_运维知识库cation, what I want to know is this running binary file name.


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()


The Qapplication parses the commandline arguemnts, the first entry is the name of the executable - this is roughly the same as argv[0] in standard C but has a few extra complexities on windows if you have a Unicode build or if the application is started as a service

See http://doc.qt.io/qt-5/qcoreapplication.html#arguments


Again not really a Qt question. To find the name of the binary file executed it would be something like.

#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
  cout << argv[0] << endl;
  return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜