Important: Please read the Qt Code of Conduct -

Xlib.h include problem

  • Hi, I'm writing a simple app that sends keystrokes to the active forms under X11.
    I need to use the header "Xlib.h".
    After adding the header in my .h file I have this compile error:

    In file included from /usr/include/X11/Xlib.h:44:0,
                     from ../PianoJoke/qfmainwindow.h:11,
                     from ../PianoJoke/main.cpp:1:
    /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtCore/qcoreevent.h:63:9: error: expected identifier before numeric constant
             None = 0,                               // invalid event
    /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtCore/qcoreevent.h:63:9: error: expected ‘}’ before numeric constant
    /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtCore/qcoreevent.h:63:9: error: expected unqualified-id before numeric constant
    In file included from /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtGui/qwindowdefs.h:44:0,
                     from /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtWidgets/qwidget.h:44,
                     from /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtWidgets/qmainwindow.h:44,
                     from /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtWidgets/QMainWindow:1,
                     from ../PianoJoke/qfmainwindow.h:4,
                     from ../PianoJoke/main.cpp:1:
    /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtCore/qobjectdefs.h:122:5: error: ‘friend’ used outside of class
         friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
    /Dati/Qt/Qt5.11.1/5.11.1/gcc_64/include/QtCore/qobjectdefs.h:124:30: note: in expansion of macro ‘Q_ENUM_IMPL’
     #define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)

    What can I do in order to use the Xlib.h header in a Qt app?

  • Qt Champions 2019

    @mrdebug said in Xlib.h include problem:


    Can you show its content?

  • It is completely empty. The behaviour occurs just adding "#include <X11/Xlib.h>" to an empty Qt project.

    #ifndef QFMAINWINDOW_H
    #define QFMAINWINDOW_H
    #include <QMainWindow>
    #include <X11/Xlib.h>
    namespace Ui {
    class QFMainWindow;
    class QFMainWindow : public QMainWindow
        explicit QFMainWindow(QWidget *parent = 0);
        Ui::QFMainWindow *ui;

  • Qt Champions 2019

    @mrdebug Can you try

    extern "C"
      #include <X11/Xlib.h>

  • Lifetime Qt Champion


    You can also try to include Xlib.h before your Qt includes.

  • Solved by creating an external library that encapsulate the x11 layer.

Log in to reply