qt5base-lts/tests/manual
Tor Arne Vestbø 7feeb7c34b Rejig native interface plumbing
The initial approach for providing public access to native
interfaces via T::nativeInteface<I>() was based on the template
not being defined, and then having explicit instantiations of
the supported types in a source file, so that the accessors
were exported and available to the user.

This worked fine for "simple" types such as QOpenGLContext
and QOffscreenSurface, but presented a problem in the context
of classes with subclasses, such as Q{Core,Gui}Application.

To ensure that a native interface for QCoreApplication was
accessible both from QCoreApplication and its subclasses,
while at the same time preventing a native interface for
QGuiApplication to be accessible for QCoreApplication, the
nativeInterface() template function had to be declared in
each subclass. Which in turn meant specializing each native
interface once for each subclass it was available in.

This quickly became tedious to manage, and the requirements
for exposing a new native interface wasn't very clear with
all these template specializations and explicit instantiations
spread around.

To improve on this situation, while also squashing a few
other birds at the same time, we change the approach to
use type erasure. The definition of T::nativeInteface<I>()
is now inline, passing on the requested interface to a per
type (T, not I) helper function, with the interface type
flattened to a std::type_info.

The type_info requested by the user is then compared to the
available types in a single per-type (T) "switch statement",
which is a lot easier to follow for someone trying to trace
the logic of how a native interface is resolved.

We can safely rely on type_info being stable between the user
application and the Qt library as a result of exporting the
type info for each native interface, by explicitly ensuring
they have a key function. This is the same mechanism that
ensures we can safely dynamic_cast these interfaces, even
across library boundaries.

The use of a free standing templated helper function instead
of a member function in the type T, is to avoid shadowing issues,
and to not pollute the class namespace of T with the helper
function.

Since we are already changing the plumbing for how a user
resolves a native interface for a type T, we take the opportunity
to add a few extra safeguards to the machinery.

First, we add a static assert in the T::nativeInteface<I>()
definition, that ensures that only compatible interfaces,
as declared by the interface themselves, are allowed.
This ensures a compile time error when an incompatible
interface is requested, which improves on the link time
errors we had prior to this patch, and also offsets the
one downside of type erasure, namely that errors are only
caught at runtime.

Secondly, each interface meant for public consumption through
T::nativeInteface<I>() is declared with a revision, which
is checked when requesting the interface. This allows us
to bump the revision when we make breaking changes to the
interface that would have otherwise been binary incompatible.
Since the user will never see this interface due to the
revision check, they will not end up calling methods that
have been removed or renamed.

One advantage of moving to a type-erased approach for the
plumbing is that we're not longer exposing the native
interface types as part of the T::nativeInteface symbols.
This means that if we ever want to rename a native interface,
the only exported symbol that the user code relies on is
the type info. Renaming is then possible by just exporting
the type info for the old interface, but leaving it empty.
Since no class in Qt implements the old native interface,
the user will just get a nullptr back, similarly to bumping
the revision of an interface.

Change-Id: Ie50d8fb536aafe2836370caacb22afbcfaf1712a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2021-05-12 22:02:05 +02:00
..
cocoa Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
corelib/tools Use QList instead of QVector in other qtbase tests 2020-07-07 11:48:45 +02:00
diaglib CMake: Regenerate projects using pro2cmake one last time 2020-12-10 11:52:30 +01:00
dialogs Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
embeddedintoforeignwindow Fix compilation of some manual tests 2020-09-26 19:53:54 +02:00
filetest CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
foreignwindows Fix compilation of some manual tests 2020-09-26 19:53:54 +02:00
gestures Fix deprecations in manual tests 2020-12-01 20:20:11 +01:00
highdpi Add ScreenGadget utility 2021-04-19 18:45:39 +02:00
inputmethodhints Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
keypadnavigation Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
lance lance tool: fix build for Qt 6 2021-03-22 13:59:40 +01:00
markdown CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
mkspecs Updated license headers 2016-01-21 18:55:18 +00:00
network_remote_stresstest Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
network_stresstest Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
qcursor Lowercase system includes and lib names for Windows, fix cross compiling 2021-04-23 14:31:04 +03:00
qdesktopservices Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
qgraphicsitem Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qgraphicsitemgroup Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qgraphicslayout/flicker CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qhttpnetworkconnection Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
qimagereader CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qlayout Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qlocale Add the "Territory" enumerated type for QLocale 2021-04-15 20:17:49 +08:00
qmetatype CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qmimedatabase CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qnetconmonitor Remove QNetworkStatusMonitor 2021-02-06 10:28:20 +00:00
qnetworkaccessmanager/qget CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qnetworkinformation Switch QNetworkInformation manual test back to using qDebug 2021-02-07 11:10:31 +00:00
qnetworkreply Remove .prev_CMakeLists.txt files 2021-01-12 20:59:13 +01:00
qopenglcontext Rename the new platform APIs from QPlatformInterface to QNativeInterface 2020-10-07 13:03:27 +02:00
qopengltextureblitter Remove .prev_CMakeLists.txt files 2021-01-12 20:59:13 +01:00
qopenglwidget/openglwidget Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qopenglwindow/multiwindow CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qprintdevice_dump CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qscreen Get rid of all usage of QApplication:desktop 2020-10-14 06:38:43 +02:00
qssloptions CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qsslsocket Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
qstorageinfo CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qsysinfo CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qt_poll Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
qtabbar Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qtabletevent Remove .prev_CMakeLists.txt files 2021-01-12 20:59:13 +01:00
qtbug-8933 Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qtbug-52641 CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qtexteditlist Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qtexttableborders CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qtouchevent Replace QtTest headers with QTest 2020-12-22 15:20:30 +01:00
qvulkaninstance CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qwidget_zorder CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
repaint Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
rhi rhi: Pipeline cache load/save 2021-01-22 10:26:03 +01:00
shortcuts Manual shortcut test: Fix deprecation warnings about key combinations 2020-11-16 12:35:42 +01:00
socketengine Remove .prev_CMakeLists.txt files 2021-01-12 20:59:13 +01:00
startsystemmove Add QWindow::startSystemMove and startSystemResize 2020-01-28 16:52:13 +01:00
textrendering Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
touch Rejig native interface plumbing 2021-05-12 22:02:05 +02:00
touchGraphicsItem CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
transientwindow Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
triangulator CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
unc CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
wasm wasm: support all cursor shapes 2019-12-30 14:30:22 +03:00
widgetgrab Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
widgets Remove .prev_CMakeLists.txt files 2021-01-12 20:59:13 +01:00
windowchildgeometry Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
windowflags Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
windowgeometry Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
windowmodality Expunge WA_GroupLeader 2020-10-27 02:55:59 +01:00
windowtransparency CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
xcb_gl_integration CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
xembed-raster Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
xembed-widgets CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
CMakeLists.txt NetworkListManager based backend for QNetworkInformation 2021-02-02 11:10:06 +01:00
manual.pro Purge QDesktopWidget 2020-10-16 04:44:13 +02:00