W3cubDocs

/Qt 5.13

Qt Platform Headers

Some applications may need to interface Qt with other frameworks. This often means using graphics contexts or other types of native handles created by one framework with another. For example, on some platforms, QOpenGLContext offers the ability to wrap an existing native OpenGL context, instead of creating a new one. This existing native context can be created by some other third-party code.

The type of such native handles is highly platform specific and in some cases the platform plugin will need more information to adopt a handle, just the handle in itself will not be sufficient. Therefore the public API consists of functions taking or returning a QVariant that contains a platform-specific value type. See for example QOpenGLContext::setNativeHandle() and QOpenGLContext::nativeHandle(). When running on Linux/X11, using the xcb platform plugin and the GLX windowing system interface, the variant contains a QGLXNativeContext. On other platforms a different class will be used. These classes are all placed in the Qt Platform Headers module.

Platform headers can be used in conjunction with QGuiApplication::platformFunction() to give a type safe interface to platform specific functionality. It is possible for headers defined in QtPlatformHeaders to define typedefs for functions that can be returned by a platform plugin from QGuiApplication::platformFunction(). Headers in QtPlatformHeaders can also implement wrapper functions for the function pointer, giving a static function that can be called from any context after the platform integration has been created. An implementation of this pattern is QXcbWindowFunctions::setWmWindowType(). This function retrieves a function pointer from QGuiApplication::platformFunction, and executes that function if the requested function was returned.

Note: Similar to the other QPA APIs, there are no binary compatibility guarantees for these classes, meaning that an application using these classes is only guaranteed to work with the Qt version it was developed against. Unlike QPA however, source compatibility is guaranteed.

Getting Started

To include the definitions of the module's functions and classes, use the following directives:

#include <QtPlatformHeaders/QWindowsWindowFunctions>
#include <QtPlatformHeaders/QXcbWindowFunctions>

As the module is header-only, no further modifications to the .pro files are required to use it.

Note: The module name (QtPlatformHeaders) must appear in the #include directive.

Note: It is not necessary to enclose the code in #ifdef directives depending on platform.

API Reference

See also QXcbWindowFunctions and QWindowsWindowFunctions.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.13/qtplatformheaders-index.html