diff options
author | Liang Qi <liang.qi@qt.io> | 2022-10-20 13:26:14 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-10-21 15:23:19 +0000 |
commit | 86cead92aec4786603d5e81fcb8bb7bb7acd97f8 (patch) | |
tree | a47698ef5905c662a033bb9afb70433e6cbdefed | |
parent | 587a56a864c5dd5b7fb8483378e5d96cdb44b175 (diff) | |
download | qtdoc-86cead92aec4786603d5e81fcb8bb7bb7acd97f8.tar.gz |
Add more info about QX11Info alternatives
Fixes: QTBUG-103856
Task-number: QTBUG-103715
Change-Id: If66172bc4c7840a1c267c5d0d3ed4b49fee42af5
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
(cherry picked from commit c4ce5d64ed54262ce83ef24e87c2799ccae52565)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | doc/src/extras-changes.qdoc | 16 | ||||
-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 |
6 files changed, 114 insertions, 2 deletions
diff --git a/doc/src/extras-changes.qdoc b/doc/src/extras-changes.qdoc index e090c746..b67c6d16 100644 --- a/doc/src/extras-changes.qdoc +++ b/doc/src/extras-changes.qdoc @@ -111,9 +111,21 @@ \section1 Changes to Qt X11 Extras - The \qt5{qx11info.html}{\c QX11Info} class has been removed. + The \l {https://doc.qt.io/qt-5/qtx11extras-index.html}{Qt X11 Extras} module was removed in Qt 6. - Clients that still rely on the functionality can include the private + \list + \li For QX11Info::connection(), use QNativeInterface::QX11Application::connection() instead. + \li For QX11Info::display(), use QNativeInterface::QX11Application::display() instead. + \li For QX11Info::isPlatformX11(), check QNativeInterface::QX11Application existence instead. + \endlist + + Make sure to check you can get a QNativeInterface::QX11Application object from QGuiApplication, + as in the following snippet: + + \snippet snippets/porting-qx11info/testwindow.cpp 1 + + Clients that still rely on the functionality in \qt5{qx11info.html}{\c QX11Info} + class can include the private header \c {<QtGui/private/qtx11extras_p.h>} as a stopgap solution. To enable private headers use \c {QT += gui-private} with \c qmake, or add a project dependency to \c Qt::GuiPrivate with \c CMake. diff --git a/doc/src/snippets/porting-qx11info/main.cpp b/doc/src/snippets/porting-qx11info/main.cpp new file mode 100644 index 00000000..2de11ac0 --- /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 00000000..adaf9f5a --- /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 00000000..d46c75e0 --- /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 00000000..7110c5d9 --- /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 08f21c8d..ee7f4bd5 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 +} |