Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, April 2008
Get Program Name


Message 1 in thread

Hi,

I'm currently using Qt 4.3.3 and I want to get the name of my own binary under linux.
Using main's argv[0] is not an option, because I need access to the program's name during the initialization of some (global) static objects 
and they will be created before main() is called.

Any ideas ?
Gerhard

--
 [ signature omitted ] 

Message 2 in thread

On Wed April 30 2008 16:34, Gerhard Wenzl wrote:
> I'm currently using Qt 4.3.3 and I want to get the name of my own binary
> under linux. Using main's argv[0] is not an option, because I need access
> to the program's name during the initialization of some (global) static
> objects and they will be created before main() is called.
Sorry, but this is weird :)... anyway, it has nothing to do with Qt.

The only "idea" I could imagine is to grab the enviromnent variable "_" which 
in some cases points to the program that was called last. But that's a) 
platform / shell dependent and will b) not always retrieve the string you 
would expect. For example, starting a program through KDE will report "_" 
as "/opt/kde3/bin/start_kdeinit", but started from a console it will report 
the real program's path.

I would not do this. And... what could be a reason for doing what you want to 
do?

argv[0] is standard, or QCoreApplication::arguments()[0] using Qt (after the 
QApplication has been created). Everything else seems strange to me :).

HTH, René
-- 
 [ signature omitted ] 

Message 3 in thread

On Wednesday 30 April 2008 16:34:51 Gerhard Wenzl wrote:
> Hi,
>
> I'm currently using Qt 4.3.3 and I want to get the name of my own binary
> under linux. Using main's argv[0] is not an option, because I need access
> to the program's name during the initialization of some (global) static
> objects and they will be created before main() is called.
>
> Any ideas ?

There's no portable way. You have to wait for main() to run to get that 
information.

If you're on Linux, you can try to readlink("/proc/self/exe") and see if that 
helps. That's completely non-portable.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 4 in thread

Quoting Gerhard Wenzl <gerhard.wenzl@xxxxxxxxx>:

> Hi,
>
> I'm currently using Qt 4.3.3 and I want to get the name of my own
> binary under linux.
> Using main's argv[0] is not an option, because I need access to the
> program's name during the initialization of some (global) static
> objects and they will be created before main() is called.
>
> Any ideas ?

BinReloc has worked fine for me so far:
http://www.autopackage.org/docs/binreloc/

Make sure you #define ENABLE_BINRELOC or it won't do anything and  
you'll waste a lot of time wondering what's failing.

-- 
 [ signature omitted ]