Don't assume QCoreApplication::applicationName() will never change

Tests will typically create multiple QCoreApplications, some of them
with different argv[0] than others, so we can't use a static variable
to keep the cached application name.

Change-Id: Icd97527730558944473a71373326b4a82f1b7cf7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Tor Arne Vestbø 2013-09-25 17:18:38 +02:00 committed by The Qt Project
parent 1749bab565
commit f04b46f34e
2 changed files with 9 additions and 6 deletions

View File

@ -146,15 +146,17 @@ QString QCoreApplicationPrivate::macMenuBarName()
#endif
QString QCoreApplicationPrivate::appName() const
{
static QString applName;
if (applicationName.isNull()) {
#ifdef Q_OS_MAC
applName = macMenuBarName();
applicationName = macMenuBarName();
#endif
if (applName.isEmpty() && argv[0]) {
char *p = strrchr(argv[0], '/');
applName = QString::fromLocal8Bit(p ? p + 1 : argv[0]);
if (applicationName.isEmpty() && argv[0]) {
char *p = strrchr(argv[0], '/');
applicationName = QString::fromLocal8Bit(p ? p + 1 : argv[0]);
}
}
return applName;
return applicationName;
}
#endif

View File

@ -83,6 +83,7 @@ public:
~QCoreApplicationPrivate();
QString appName() const;
mutable QString applicationName;
#ifdef Q_OS_MAC
static QString macMenuBarName();