diff options
author | Liang Qi <liang.qi@qt.io> | 2022-10-20 13:26:14 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2022-10-21 11:19:52 +0000 |
commit | c4ce5d64ed54262ce83ef24e87c2799ccae52565 (patch) | |
tree | 0548484fda439ee2642588954a1d1d70378e7b2b /doc/src/snippets | |
parent | f9d56ead72053f3c90e69d88a4060da9f72abff9 (diff) |
Add more info about QX11Info alternatives
Pick-to: 6.4 6.2
Fixes: QTBUG-103856
Task-number: QTBUG-103715
Change-Id: If66172bc4c7840a1c267c5d0d3ed4b49fee42af5
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'doc/src/snippets')
-rw-r--r-- | doc/src/snippets/porting-qx11info/main.cpp | 16 | ||||
-rw-r--r-- | doc/src/snippets/porting-qx11info/porting-qx11info.pro | 9 | ||||
-rw-r--r-- | doc/src/snippets/porting-qx11info/testwindow.cpp | 55 | ||||
-rw-r--r-- | doc/src/snippets/porting-qx11info/testwindow.h | 16 | ||||
-rw-r--r-- | doc/src/snippets/snippets.pro | 4 |
5 files changed, 100 insertions, 0 deletions
diff --git a/doc/src/snippets/porting-qx11info/main.cpp b/doc/src/snippets/porting-qx11info/main.cpp new file mode 100644 index 000000000..2de11ac0c --- /dev/null +++ b/doc/src/snippets/porting-qx11info/main.cpp @@ -0,0 +1,16 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "testwindow.h" + +#include <QtGui/QGuiApplication> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + TestWindow win; + win.show(); + + return app.exec(); +} diff --git a/doc/src/snippets/porting-qx11info/porting-qx11info.pro b/doc/src/snippets/porting-qx11info/porting-qx11info.pro new file mode 100644 index 000000000..adaf9f5ac --- /dev/null +++ b/doc/src/snippets/porting-qx11info/porting-qx11info.pro @@ -0,0 +1,9 @@ +lessThan(QT_MAJOR_VERSION, 6) { + QT += x11extras +} + +LIBS += -lxcb -lX11 + +HEADERS = testwindow.h +SOURCES += testwindow.cpp \ + main.cpp diff --git a/doc/src/snippets/porting-qx11info/testwindow.cpp b/doc/src/snippets/porting-qx11info/testwindow.cpp new file mode 100644 index 000000000..d46c75e0e --- /dev/null +++ b/doc/src/snippets/porting-qx11info/testwindow.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "testwindow.h" + +//! [0] +#include <QtGui/QGuiApplication> +//! [0] +#include <QDebug> + +#if defined(Q_OS_UNIX) +#if QT_VERSION < 0x060000 +#include <QtX11Extras/QX11Info> +#endif +#endif + +#include <X11/Xlib.h> +#include <xcb/xcb.h> + +TestWindow::TestWindow(QWindow *parent) + : QWindow(parent) +{ + +#if QT_VERSION < 0x060000 + Display *display = QX11Info::display(); + xcb_connection_t *connection = QX11Info::connection(); + bool isPlatformX11 = QX11Info::isPlatformX11(); +#else +//! [1] + Display *display = nullptr; + xcb_connection_t *connection = nullptr; + bool isPlatformX11 = false; + if (auto *x11Application = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()) { + display = x11Application->display(); + connection = x11Application->connection(); + isPlatformX11 = true; + } + // or + // isPlatformX11 = qGuiApp->nativeInterface<QNativeInterface::QX11Application>(); +//! [1] +#endif + + qDebug() << "Display *display=" << display; + if (display) + qDebug() << "XConnectionNumber=" << XConnectionNumber(display); + + qDebug() << "xcb_connection_t *xcbConnection=" << connection; + if (connection) { + const xcb_setup_t *xcbSetup = xcb_get_setup(connection); + if (xcbSetup) + qDebug() << "protocol_major_version=" << xcbSetup->protocol_major_version << ", protocol_minor_version=" << xcbSetup->protocol_minor_version; + } + + qDebug() << "isPlatformX11=" << isPlatformX11; +} diff --git a/doc/src/snippets/porting-qx11info/testwindow.h b/doc/src/snippets/porting-qx11info/testwindow.h new file mode 100644 index 000000000..7110c5d91 --- /dev/null +++ b/doc/src/snippets/porting-qx11info/testwindow.h @@ -0,0 +1,16 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef TESTWINDOW_H +#define TESTWINDOW_H + +#include <QtGui/QWindow> + +class TestWindow : public QWindow +{ + Q_OBJECT +public: + explicit TestWindow(QWindow *parent = nullptr); +}; + +#endif // TESTWINDOW_H diff --git a/doc/src/snippets/snippets.pro b/doc/src/snippets/snippets.pro index 08f21c8d3..ee7f4bd5c 100644 --- a/doc/src/snippets/snippets.pro +++ b/doc/src/snippets/snippets.pro @@ -90,3 +90,7 @@ SUBDIRS = brush \ # whatsthis \ widget-mask \ xml + +qtConfig(xcb) { + SUBDIRS += porting-qx11info +} |