summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-14 00:50:29 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-17 02:23:17 +0200
commit0e7212460ba7fab19a47f960b09a011973a7c475 (patch)
tree6801ba8a3e6e43c1a924411b965248e6f7bc2f8a /src/corelib
parent8ebd4a1da820cff0e499258f79a3fc139ea06b77 (diff)
Use member function instead of template function to resolve native interface
The use of a freestanding function is not needed now that the name doesn't alias the nativeInterface accessor function, and was just adding complexity to the machinery. People not familiar with the code will have an easier time following the flow through the helper member function, and we no longer need to declare our own export macros. Pick-to: 6.2 Change-Id: I17530b7e89939cfc19ab8ffaa076b7129ae02dcf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qnativeinterface.h52
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp5
2 files changed, 25 insertions, 32 deletions
diff --git a/src/corelib/global/qnativeinterface.h b/src/corelib/global/qnativeinterface.h
index 395a4ba1da..5e5c78beec 100644
--- a/src/corelib/global/qnativeinterface.h
+++ b/src/corelib/global/qnativeinterface.h
@@ -43,14 +43,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qloggingcategory.h>
-#ifndef QT_STATIC
-# define Q_NATIVE_INTERFACE_EXPORT Q_DECL_EXPORT
-# define Q_NATIVE_INTERFACE_IMPORT Q_DECL_IMPORT
-#else
-# define Q_NATIVE_INTERFACE_EXPORT
-# define Q_NATIVE_INTERFACE_IMPORT
-#endif
-
QT_BEGIN_NAMESPACE
// We declare a virtual non-inline function in the form
@@ -166,9 +158,6 @@ namespace QNativeInterface::Private {
template <typename I>
struct NativeInterface : TypeInfo<I> {};
- template <typename T>
- Q_NATIVE_INTERFACE_IMPORT void *resolveInterface(const T *that, const char *name, int revision);
-
Q_CORE_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcNativeInterface)
} // QNativeInterface::Private
@@ -179,10 +168,12 @@ namespace QNativeInterface::Private {
typename BaseType = T, std::enable_if_t<TypeInfo::template isCompatibleWith<T>, bool> = true> \
NativeInterface *nativeInterface() const \
{ \
- return static_cast<NativeInterface*>( \
- QNativeInterface::Private::resolveInterface(this, \
- TypeInfo::name(), TypeInfo::revision())); \
- }
+ return static_cast<NativeInterface*>(resolveInterface( \
+ TypeInfo::name(), TypeInfo::revision())); \
+ } \
+ protected: \
+ void *resolveInterface(const char *name, int revision) const; \
+ public:
// Provides a definition for the interface destructor
#define QT_DEFINE_NATIVE_INTERFACE_2(Namespace, InterfaceClass) \
@@ -192,22 +183,25 @@ namespace QNativeInterface::Private {
#define QT_DEFINE_PRIVATE_NATIVE_INTERFACE(...) QT_OVERLOADED_MACRO(QT_DEFINE_NATIVE_INTERFACE, QNativeInterface::Private, __VA_ARGS__)
#define QT_NATIVE_INTERFACE_RETURN_IF(NativeInterface, baseType) \
- using QNativeInterface::Private::lcNativeInterface; \
- qCDebug(lcNativeInterface, "Comparing requested interface name %s with available %s", \
- name, TypeInfo<NativeInterface>::name()); \
- if (qstrcmp(name, TypeInfo<NativeInterface>::name()) == 0) { \
- qCDebug(lcNativeInterface, "Match for interface %s. Comparing revisions (requested %d / available %d)", \
- name, revision, TypeInfo<NativeInterface>::revision()); \
- if (revision == TypeInfo<NativeInterface>::revision()) { \
- qCDebug(lcNativeInterface) << "Full match. Returning dynamic cast of" << baseType; \
- return dynamic_cast<NativeInterface*>(baseType); \
+ { \
+ using QNativeInterface::Private::lcNativeInterface; \
+ using QNativeInterface::Private::TypeInfo; \
+ qCDebug(lcNativeInterface, "Comparing requested interface name %s with available %s", \
+ name, TypeInfo<NativeInterface>::name()); \
+ if (qstrcmp(name, TypeInfo<NativeInterface>::name()) == 0) { \
+ qCDebug(lcNativeInterface, "Match for interface %s. Comparing revisions (requested %d / available %d)", \
+ name, revision, TypeInfo<NativeInterface>::revision()); \
+ if (revision == TypeInfo<NativeInterface>::revision()) { \
+ qCDebug(lcNativeInterface) << "Full match. Returning dynamic cast of" << baseType; \
+ return dynamic_cast<NativeInterface*>(baseType); \
+ } else { \
+ qCWarning(lcNativeInterface, "Native interface revision mismatch (requested %d / available %d) for interface %s", \
+ revision, TypeInfo<NativeInterface>::revision(), name); \
+ return nullptr; \
+ } \
} else { \
- qCWarning(lcNativeInterface, "Native interface revision mismatch (requested %d / available %d) for interface %s", \
- revision, TypeInfo<NativeInterface>::revision(), name); \
- return nullptr; \
+ qCDebug(lcNativeInterface, "No match for requested interface name %s", name); \
} \
- } else { \
- qCDebug(lcNativeInterface, "No match for requested interface name %s", name); \
}
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 81ea3dc5be..8f53790cb7 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -3246,10 +3246,9 @@ QCoreApplication::checkPermission(const QString &permission)
}
#endif // future && QT_NO_QOBJECT
-template <>
-Q_NATIVE_INTERFACE_EXPORT void *QNativeInterface::Private::resolveInterface(const QCoreApplication *that, const char *name, int revision)
+void *QCoreApplication::resolveInterface(const char *name, int revision) const
{
- Q_UNUSED(that); Q_UNUSED(name); Q_UNUSED(revision);
+ Q_UNUSED(name); Q_UNUSED(revision);
return nullptr;
}