QT5 QPlatformNativeInterface and HWND
Asked Answered
H

4

16

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)

Homosexuality answered 15/3, 2013 at 12:25 Comment(0)
N
13

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.

Nigger answered 21/3, 2013 at 19:14 Comment(2)
what about external build system like CMAKE?Homosexuality
I'm not familiar with CMAKE. :( But I guess you need to find some way to add -I[include_path]/QtGui/[version]/QtGui to Makefiles. Maybe looking at qmake sources could help...Nigger
M
11

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>
Machicolate answered 29/1, 2014 at 17:47 Comment(0)
H
1

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.

Homosexuality answered 15/3, 2013 at 12:47 Comment(0)
R
0

Actually winId() should work fine, BUT you should keep in mind a fact (which is not mentioned in an answer you linked to), that this HWND will be generated UPON request. That's the way Qt works, its using owner draw facility and don't create standard windows handles for everything (you can see this for example you Spy from MSDN), but as soon as you are asking for HWND it will create an appropriate entity and return you a valid HWND, so it will be visible for Spy (you can try this on any standard widget)

Revocable answered 4/4, 2016 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.