Fix applicationName() being empty in QApplication.
A virtual method was reimplemented to return an always-empty string, probably a leftover from a refactoring. This fix showed that tst_qwidget_window was buggy: between Qt4 and Qt5, a "Before" became "After", which made "Before" unused, and was masking the fact that the app name was empty by default. In addition, the earlier Qt5 change that made the app name default to argv[0] now requires updating this test, now that it's actually working. Change-Id: I5360026821a9b95bedd0ff09dba3d51a22e542b7 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Paul Olav Tvete <paul.tvete@nokia.com>
This commit is contained in:
parent
cbddca5f02
commit
199741d026
@ -78,7 +78,7 @@ public:
|
||||
|
||||
void _q_initializeProcessManager();
|
||||
|
||||
virtual QString appName() const;
|
||||
QString appName() const;
|
||||
virtual void createEventDispatcher();
|
||||
static void removePostedEvent(QEvent *);
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -135,7 +135,6 @@ public:
|
||||
|
||||
|
||||
void createEventDispatcher();
|
||||
QString appName() const;
|
||||
static void dispatchEnterLeave(QWidget *enter, QWidget *leave);
|
||||
|
||||
//modality
|
||||
|
@ -71,7 +71,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static QString appName;
|
||||
static QString appFont;
|
||||
static bool popupGrabOk = false;
|
||||
static QPointer<QWidget> autoGrabber;
|
||||
@ -80,11 +79,6 @@ extern QWidget *qt_popup_down;
|
||||
extern bool qt_replay_popup_mouse_event;
|
||||
int openPopupCount = 0;
|
||||
|
||||
QString QApplicationPrivate::appName() const
|
||||
{
|
||||
return QT_PREPEND_NAMESPACE(appName);
|
||||
}
|
||||
|
||||
void QApplicationPrivate::createEventDispatcher()
|
||||
{
|
||||
QGuiApplicationPrivate::createEventDispatcher();
|
||||
@ -456,7 +450,6 @@ void qt_init(QApplicationPrivate *priv, int type)
|
||||
if (const QPalette *toolTipPalette = QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::ToolTipPalette))
|
||||
QToolTip::setPalette(*toolTipPalette);
|
||||
QApplicationPrivate::initializeWidgetFontHash();
|
||||
qApp->setObjectName(appName);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -101,6 +101,7 @@ private slots:
|
||||
|
||||
void args_data();
|
||||
void args();
|
||||
void appName();
|
||||
|
||||
void lastWindowClosed();
|
||||
void quitOnLastWindowClosed();
|
||||
@ -489,6 +490,16 @@ void tst_QApplication::args()
|
||||
delete [] argv;
|
||||
}
|
||||
|
||||
void tst_QApplication::appName()
|
||||
{
|
||||
char argv0[] = "tst_qapplication";
|
||||
char *argv[] = { argv0, 0 };
|
||||
int argc = 1;
|
||||
QApplication app(argc, argv);
|
||||
QCOMPARE(::qAppName(), QString::fromLatin1("tst_qapplication"));
|
||||
QCOMPARE(QCoreApplication::applicationName(), QString::fromLatin1("tst_qapplication"));
|
||||
}
|
||||
|
||||
class CloseWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -187,21 +187,28 @@ void tst_QWidget_window::tst_windowFilePathAndwindowTitle_data()
|
||||
QTest::addColumn<QString>("finalTitleAfter");
|
||||
|
||||
QString validPath = QApplication::applicationFilePath();
|
||||
QString appName = QLatin1String("Killer App");
|
||||
QString fileNameOnly = QFileInfo(validPath).fileName() + QLatin1String("[*]");
|
||||
QString fileAndApp = fileNameOnly + QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ") + appName;
|
||||
QString fileAndSep = fileNameOnly + QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ");
|
||||
QString windowTitle = QLatin1String("Here is a Window Title");
|
||||
|
||||
QTest::newRow("never Set Title nor AppName") << false << false << validPath << QString() << windowTitle << fileNameOnly << fileNameOnly;
|
||||
QTest::newRow("set title after only, but no AppName") << false << true << validPath << QString() << windowTitle << fileNameOnly << windowTitle;
|
||||
QString defaultPlatString =
|
||||
#if 0 // was ifdef Q_OS_MAC, but that code is disabled in qwidget.cpp and caption handling should move to QPA anyway
|
||||
fileNameOnly;
|
||||
#else
|
||||
fileAndSep + "tst_qwidget_window"; // default app name in Qt5
|
||||
#endif
|
||||
|
||||
QTest::newRow("never Set Title nor AppName") << false << false << validPath << QString() << windowTitle << defaultPlatString << defaultPlatString;
|
||||
QTest::newRow("set title after only, but no AppName") << false << true << validPath << QString() << windowTitle << defaultPlatString << windowTitle;
|
||||
QTest::newRow("set title before only, not AppName") << true << false << validPath << QString() << windowTitle << windowTitle << windowTitle;
|
||||
QTest::newRow("always set title, not appName") << true << true << validPath << QString() << windowTitle << windowTitle << windowTitle;
|
||||
|
||||
QString appName = QLatin1String("Killer App");
|
||||
QString platString =
|
||||
#ifdef Q_OS_MAC
|
||||
#if 0 // was ifdef Q_OS_MAC, but that code is disabled in qwidget.cpp and caption handling should move to QPA anyway
|
||||
fileNameOnly;
|
||||
#else
|
||||
fileAndApp;
|
||||
fileAndSep + appName;
|
||||
#endif
|
||||
|
||||
QTest::newRow("never Set Title, yes AppName") << false << false << validPath << appName << windowTitle << platString << platString;
|
||||
@ -233,20 +240,13 @@ void tst_QWidget_window::tst_windowFilePathAndwindowTitle()
|
||||
widget.setWindowTitle(indyWindowTitle);
|
||||
}
|
||||
widget.setWindowFilePath(filePath);
|
||||
#ifdef Q_OS_MAC
|
||||
QEXPECT_FAIL("never Set Title, yes AppName", "QTBUG-23682", Continue);
|
||||
QEXPECT_FAIL("set title after only, yes AppName", "QTBUG-23682", Continue);
|
||||
#endif
|
||||
QCOMPARE(finalTitleBefore, widget.windowTitle());
|
||||
QCOMPARE(widget.windowTitle(), finalTitleBefore);
|
||||
QCOMPARE(widget.windowFilePath(), filePath);
|
||||
|
||||
if (setWindowTitleAfter) {
|
||||
widget.setWindowTitle(indyWindowTitle);
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
QEXPECT_FAIL("never Set Title, yes AppName", "QTBUG-23682", Continue);
|
||||
#endif
|
||||
QCOMPARE(finalTitleAfter, widget.windowTitle());
|
||||
QCOMPARE(widget.windowTitle(), finalTitleAfter);
|
||||
QCOMPARE(widget.windowFilePath(), filePath);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user