diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 3ee1c54826..fe40e05536 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -792,6 +793,15 @@ void QGuiApplication::setDesktopFileName(const QString &name) if (!QGuiApplicationPrivate::desktopFileName) QGuiApplicationPrivate::desktopFileName = new QString; *QGuiApplicationPrivate::desktopFileName = name; + if (name.endsWith(QLatin1String(".desktop"))) { // ### Qt 7: remove + const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name); + if (!filePath.isEmpty()) { + qWarning("QGuiApplication::setDesktopFileName: the specified desktop file name " + "ends with .desktop. For compatibility reasons, the .desktop suffix will " + "be removed. Please specify a desktop file name without .desktop suffix"); + (*QGuiApplicationPrivate::desktopFileName).chop(8); + } + } } QString QGuiApplication::desktopFileName() diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 5a206d8177..8542ce300f 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -122,8 +122,8 @@ void tst_QGuiApplication::desktopFileName() QCOMPARE(QGuiApplication::desktopFileName(), QString()); - QGuiApplication::setDesktopFileName("io.qt.QGuiApplication.desktop"); - QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication.desktop")); + QGuiApplication::setDesktopFileName("io.qt.QGuiApplication"); + QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication")); QGuiApplication::setDesktopFileName(QString()); QCOMPARE(QGuiApplication::desktopFileName(), QString());