Get XCB connection for QWindow
-
How do I get the XCB connection (
xcb_connection_t*
) for a givenQWindow
in Qt5 on X11?Right now I'm using
QX11Info::connection()
to retrieve this pointer, but that depends onlibQt5X11Extras.so
, which might not be available on every target system. Alternatively, I could useQPlatformNativeInterface::nativeResourceForWindow()
with "connection" as the first argument, butQPlatformNativeInterface
is non-stable and might change between minor Qt releases.Background: I'm integrating a wgpu-based renderer in a Qt application and need the native handle of the QWindow (window ID and connection pointer) to create the swapchain surface. This is working so far, but I'd like to remove the dependency on libQt5X11Extras, if possible.
Any help would be greatly appreciated.
-
@adwn said in Get XCB connection for QWindow:
libQt5X11Extras.so, which might not be available on every target system
It should be available on all systems which have X11.
Of course it will not be available on system without X11, but there you also can't use XCB connection as there is no such thing. So, don't know what the problem is? -
@jsulm Available, yes, but not necessarily installed. For example, on Ubuntu 20.04, none of the other Qt packages seems to depend on
libqt5x11extras
, even on X11 systems. It's not a show-stopper, because the user can manually install this package after getting a cryptic error message when trying to launch my app, but it's a small annoyance I'd like to avoid. -
Hi,
How is your application installed ?
One alternative is to embed that code directly into your application with proper credit given to that piece.
-
@SGaist said in Get XCB connection for QWindow:
How is your application installed ?
It's a single executable which is copied to the target machine :-)
One alternative is to embed that code directly into your application with proper credit given to that piece.
The
QX11Info::connection()
method I'm using is essentially this code:QPlatformNativeInterface *native = qApp->platformNativeInterface(); void *connection = native->nativeResourceForIntegration(QByteArray("connection"));
Unfortunately, that depends on
QPlatformNativeInterface
. So if I want to call a method on this instance, I have to includeqpa/qplatformnativeinterface.h
which is unstable and which might cause the application to break if the user has installed Qt 5.15 instead of 5.12, for example. -
That's one risk indeed.
One thing you also have to take into account is that the various extras modules have been removed in Qt 6y