summaryrefslogtreecommitdiffstats
path: root/src/corelib/compat/removed_api.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-05-20 22:33:11 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-03-15 11:36:09 +0100
commit9da4c6bfb70b5ea444b74ef05f1122d5983734e1 (patch)
tree112898831160a579c506aa96f239abfb062d8b19 /src/corelib/compat/removed_api.cpp
parent6313a1adf5b04cb06b9630110f2be9cada6aeb44 (diff)
QObject: port setObjectName() to QAnyStringView
... while keeping the QString overload for users that pass actual QStrings (e.g. QStringLiteral). However, QString and QAnyStringView cannot be overloaded (they're ambiguous for most arguments), so we need to make one of them a Q_WEAK_OVERLOAD. Normally, we'd make the new function weak and keep the old function as-is, but, here, that would be beside the point, because all callers would continue to resolve to the QString overload, and nothing would call the QAnyStringView one. So we really want the old function to be the Q_WEAK_OVERLOAD, so that the QString overload is only selected when actual QStrings are passed. That means we need to leave the old function in a compat build (compiled in, but not visible in the public header). Since Q_WEAK_OVERLOADs cannot be (easily) exported (they're templates), make it call a private function (which can be, and is, exported). Reviewers may questions whether one can overload setObjectName() and template <typename = void> setObjectName() The answer is that we can, because templates mangle differently from normal functions. We can even call the template function (with explicit template arguments), as seen in removed_api.cpp. This adapts the interface of the function to how most users use it: They pass QLatin1String or just const char[]. Only very few passed QStringLiteral, which, ignoring that fact that it produces a ton of code for the temporary QString's destructor that's never executed, would have been, and continues to be, the optimal way of passing data, modulo plugin bugs (QTBUG-51602, QTBUG-49061). [ChangeLog][QtCore][QObject] Added setObjectName() overload taking QAnyStringView. Fixes: QTBUG-101393 Change-Id: I1243545614754b4978d4c8641460980b6b293c1a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/compat/removed_api.cpp')
-rw-r--r--src/corelib/compat/removed_api.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp
index b856f6b495..64c3e9ccff 100644
--- a/src/corelib/compat/removed_api.cpp
+++ b/src/corelib/compat/removed_api.cpp
@@ -205,6 +205,15 @@ QCalendar::QCalendar(QStringView name)
QCalendar::QCalendar(QLatin1String name)
: QCalendar(QAnyStringView{name}) {}
+
+#include "qobject.h"
+
+void QObject::setObjectName(const QString &name)
+{
+ setObjectName<void>(name);
+}
+
+
#include "qversionnumber.h"
QT_WARNING_PUSH
@@ -229,5 +238,6 @@ QT_WARNING_POP
// #include <qotherheader.h>
// // implement removed functions from qotherheader.h
+// order sections alphabetically to reduce chances of merge conflicts
#endif // QT_CORE_REMOVED_SINCE(6, 4)