Regarding QCoreApplication::applicationDirPath() and stripping the path from argv[0] in KCmdLineArgs

David Faure faure at kde.org
Thu Oct 15 12:57:58 BST 2009


On Thursday 15 October 2009, George Kiagiadakis wrote:
> The problem:
> 
> The real problem here is that QCoreApplication::applicationDirPath()
> relies on argv[0] for finding the path and falls back to looking in
> $PATH if argv[0] does not contain a path. However, KCmdLineArgs for
> some strange reason strips the path from argv[0], discarding this
> valuable information. This happens in kcmdlineargs.cpp line 466:
> 
> ------------
>    // Strip path from argv[0]
>    if (s->argc) {
>      char *p = strrchr( s->argv[0], '/');
>      if (p)
>        s->argv[0] = p+1;
>    }
> -----------
> 
> And my question is, why is the path stripped there? Is there a good
> reason? Could I just get rid of this code?

Let me tell you about svn annotate ;-)
$ svn ann kcmdlineargs.cpp | grep Strip
 38560       waba    // Strip path from argv[0]
$ svn log -r38560 kcmdlineargs.cpp
WABA:
* Display argv[0] instead of appname.

Indeed,
$ konqueror --help
Usage: konqueror [Qt-options] [KDE-options] [...]
shows "konqueror", not the internal appname (from kcomponentdata, could be 
different in some cases I guess), nor the full path to konqueror.

> Maybe we could have a
> separate variable with the stripped argv[0] if it is needed for some
> purpose and pass the original one to QApplication?

Yep, sounds like a solution. For "some purpose", see KCmdLineArgs::appName,
KCmdLineArgs::usageError, KCmdLineArgs::usage. Basically all uses of argv[0] 
except when passing it to Qt.

KCmdLineArgs::init() is strange, it seems to do the opposite of what Waldo's 
commit was about, it uses the KAboutData appName as argv[0], this needs 
investigation.

-- 
David Faure, faure at kde.org, sponsored by Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list