From e9aaf017c200b393668e3b4aa1456e355f07bcb6 Mon Sep 17 00:00:00 2001
From: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Date: Mon, 10 Oct 2016 16:57:22 +0100
Subject: [PATCH] Project wizards: warn when using deprecated APIs in new
 projects

As discussed at QtCS, almost none of our users know that they can
get warnings when they use deprecated APIs, and/or disable them
altogether. A first step would be getting the relevant defines added
by the new project wizards.

Change-Id: I5d4260b5aa094ac2a077b7b00eaa577108e5f612
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
---
 .../wizards/projects/qmake/consoleapp/file.pro      | 11 +++++++++++
 .../projects/qmake/qtcanvas3dapplication/app.pro    | 11 +++++++++++
 .../projects/qmake/qtquickapplication/app.pro       | 11 +++++++++++
 .../qmake/qtquickcontrols2application/app.pro       | 11 +++++++++++
 .../qmake/qtquickcontrolsapplication/app.pro        | 11 +++++++++++
 .../wizards/qtprojectparameters.cpp                 | 13 +++++++++++++
 6 files changed, 68 insertions(+)

diff --git a/share/qtcreator/templates/wizards/projects/qmake/consoleapp/file.pro b/share/qtcreator/templates/wizards/projects/qmake/consoleapp/file.pro
index ad2b74f649..9df9214a84 100644
--- a/share/qtcreator/templates/wizards/projects/qmake/consoleapp/file.pro
+++ b/share/qtcreator/templates/wizards/projects/qmake/consoleapp/file.pro
@@ -10,3 +10,14 @@ CONFIG -= app_bundle
 TEMPLATE = app
 
 SOURCES += %{MainCppName}
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
diff --git a/share/qtcreator/templates/wizards/projects/qmake/qtcanvas3dapplication/app.pro b/share/qtcreator/templates/wizards/projects/qmake/qtcanvas3dapplication/app.pro
index 91b0337e7b..e211b30bfa 100644
--- a/share/qtcreator/templates/wizards/projects/qmake/qtcanvas3dapplication/app.pro
+++ b/share/qtcreator/templates/wizards/projects/qmake/qtcanvas3dapplication/app.pro
@@ -11,6 +11,17 @@ RESOURCES += qml.qrc
 # Additional import path used to resolve QML modules in Qt Creator's code model
 QML_IMPORT_PATH =
 
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
diff --git a/share/qtcreator/templates/wizards/projects/qmake/qtquickapplication/app.pro b/share/qtcreator/templates/wizards/projects/qmake/qtquickapplication/app.pro
index 5eecb7b319..cef1a05e98 100644
--- a/share/qtcreator/templates/wizards/projects/qmake/qtquickapplication/app.pro
+++ b/share/qtcreator/templates/wizards/projects/qmake/qtquickapplication/app.pro
@@ -13,6 +13,17 @@ QML_IMPORT_PATH =
 # Additional import path used to resolve QML modules just for Qt Quick Designer
 QML_DESIGNER_IMPORT_PATH =
 
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
diff --git a/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrols2application/app.pro b/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrols2application/app.pro
index 3308ed251c..190b79c9e5 100644
--- a/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrols2application/app.pro
+++ b/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrols2application/app.pro
@@ -12,6 +12,17 @@ QML_IMPORT_PATH =
 # Additional import path used to resolve QML modules just for Qt Quick Designer
 QML_DESIGNER_IMPORT_PATH =
 
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
diff --git a/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrolsapplication/app.pro b/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrolsapplication/app.pro
index 227fd03489..7c8a5e31d5 100644
--- a/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrolsapplication/app.pro
+++ b/share/qtcreator/templates/wizards/projects/qmake/qtquickcontrolsapplication/app.pro
@@ -18,6 +18,17 @@ QML_IMPORT_PATH =
 # Additional import path used to resolve QML modules just for Qt Quick Designer
 QML_DESIGNER_IMPORT_PATH =
 
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
diff --git a/src/plugins/qmakeprojectmanager/wizards/qtprojectparameters.cpp b/src/plugins/qmakeprojectmanager/wizards/qtprojectparameters.cpp
index ed71f55b5a..e97a4d1ab5 100644
--- a/src/plugins/qmakeprojectmanager/wizards/qtprojectparameters.cpp
+++ b/src/plugins/qmakeprojectmanager/wizards/qtprojectparameters.cpp
@@ -112,6 +112,19 @@ void QtProjectParameters::writeProFile(QTextStream &str) const
 
     if (!targetDirectory.isEmpty())
         str << "\nDESTDIR = " << targetDirectory << '\n';
+
+    if (qtVersionSupport != SupportQt4Only) {
+        str << "\n"
+               "# The following define makes your compiler emit warnings if you use\n"
+               "# any feature of Qt which as been marked as deprecated (the exact warnings\n"
+               "# depend on your compiler). Please consult the documentation of the\n"
+               "# deprecated API in order to know how to port your code away from it.\n"
+               "DEFINES += QT_DEPRECATED_WARNINGS\n\n"
+               "# You can also make your code fail to compile if you use deprecated APIs.\n"
+               "# In order to do so, uncomment the following line.\n"
+               "# You can also select to disable deprecated APIs only up to a certain version of Qt.\n"
+               "#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0\n";
+    }
 }
 
 void QtProjectParameters::writeProFileHeader(QTextStream &str)
-- 
GitLab