Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get executable name in Qt

Tags:

qt

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

like image 639
Frank Avatar asked Dec 23 '10 03:12

Frank


People also ask

How do I change my Qt application name?

You can go to the Designer in Qt Creator and change the title of the object in settings,which are on the right side.

How do I make my QT file executable?

From: How to create executable file for a Qt Application? Basically you have to look for MinGW subfolder deep into Qt tree, where Qt utilities reside, and copy needed dll's. These are the steps I follow, based upon Qt 4.7. 4, for packaging the application with correct shared libraries.

How can I get Qt process ID?

Given its full path, you can easily get the name of the executable using QFileInfo::fileName() . Or QFileInfo( QCoreApplication::applicationFilePath() ). fileName() for the filename of the executable.


1 Answers

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() 
like image 169
André Avatar answered Oct 05 '22 23:10

André