Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT5 QPlatformNativeInterface and HWND

Tags:

qt5

hwnd

qtgui

wid

In one of the answers to Get HWND on windows with Qt5 (from WId) it is suggested to employ QPlatformNativeInterface in order to recover the native window handler.

To access the QT header though the example uses its full path:

#include <QtGui/5.0.0/QtGui/qpa/qplatformnativeinterface.h>

This, of course, is not acceptable as a definitive solution. Is there a way to include QPlatformNativeInterface using the default inclusion system of QT?

Notice that neither

#include <QPlatformNativeInterface> 

works (this file is not generated during the default QT build)

nor

#include <QGuiApplication>

works (which only contains a forward declaration of QPlatformNativeInterface)

like image 259
Pierluigi Avatar asked Mar 15 '13 12:03

Pierluigi


3 Answers

You can use

QT += gui-private

in your project file, as in the example plugin, and then just

#include <qpa/qplatformnativeinterface.h>

should work (works for me at least).

These APIs are indeed private, but if you have to use them, I guess this is better than adding an #ifdef for each version.

like image 145
jkozera Avatar answered Oct 19 '22 18:10

jkozera


For CMake, you'll have to use this:

find_package(Qt5Gui)
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})

and then use the normal include for your source file:

#include <qpa/qplatformnativeinterface.h>
like image 40
axelstudios Avatar answered Oct 19 '22 20:10

axelstudios


By searching a little bit more it seems that QPlatformNativeInterface is currently private and will be made public as part of the Qt Platform Abstraction when this library will stabilize.

like image 1
Pierluigi Avatar answered Oct 19 '22 18:10

Pierluigi