Right way to include Qtxxx/private headers in Qt5 ?

  • I am trying to move a project from Qt4.x to Qt5.x. The project is built with Visual Studio 2013.
    At present, I met a problem. Since Qt 5, some APIs/classes are changed. I need to use some classes in QtGui/private, QtGui/qpa, QtCore/private. Like these

    #include <QtGui/private/qguiapplication_p.h>
    #include <QtGui/qpa/qplatformintegration.h>
    #include <QtGui/qpa/qplatforminputcontext.h>

    For this purpose, I need to add these to Include path


    Some people say that add QT += gui-private to the .pro would work. This makes me confused, Because my project is built with Visual Studio.
    What's more, we can include all QtWidgets header by using

    #include <QtWidgets/QtWidgets>

    Is there a way to include all private headers. Is there a configure param( If I build Qt from source myself). Such as

    #include <QtGui/private>
    #include <QtGui/qpa>

    Or I need to make the file private/qpa myselft ?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    No there's no global private nor qpa include.

    What private API do you need ? Especially from QPA ?

  • @SGaist Thanks for reply.
    I have code like this

    // inputContext is from QWidget
    QInputContext* ic = inputContext();
    if (ic)

    In Qt5, inputContext seems being removed, and QInputContext either.
    After making the changes, the code as below

    QPlatformInputContext* ic = QGuiApplicationPrivate::platformIntegration()->inputContext();
    if (ic)
       // some other code
       ic->update(Qt::ImAbsolutePosition);  // In order to Adjust position of IME

    API from QtGui/private and QtGui/qpa.

  • Lifetime Qt Champion

    What about QGuiApplication::inputMethod and QInputMethod::update ? Both are public API

  • @SGaist Thanks. I will have a try.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.