Wrong QT_VERSION define dedected within Qt Creator



  • Hey,

    I use cmake files to build my Projects and have Qt 4.8 , Qt 5.1 and Qt 5.2 installed Qt 4.8 where installed through the package manager (yum). However, I use Qt 5.2 in my current Project and can compile it, but when I add a new Form file with .cpp and .hpp file, Qt creator adds the following line in the .hpp file.
    @
    #if QT_VERSION >= 0x050000
    #include <QtWidgets/QDockWidget>
    #else
    #include <QtGui/QDockWidget>
    #endif
    @

    If I leave it that way my program crashes, because the define QT_VERSION is from the system qglobal.h file which is Qt version 4.8. But the project is setup for Qt version 5.2.
    Has anybody an idea why this happens?

    Thanks in advance,
    chris


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure Qt Creator is setup correctly ? Kits/Qt Versions ?



  • I think so! :-)

    Kits:
    Auto-detected

    • Desktop Qt 5.2.0 GCC 64bit (default) "Pointing to Qt version 5.2.0"

    Manual

    • Qt4 "Pointing to Qt version Qt 4.8.5 (System)"
    • Qt5 "Pointing to Qt version Qt 5.1.0"

    Qt Versions (Path)

    • /opt/Qt5.2.0/5.2.0/gcc_64/bin/
    • /opt/Qt5/5.1.0/gcc_64/bin/qmake
    • /usr/bin/qmake-qt4

  • Moderators

    Hi,

    [quote author="chrislux" date="1390655909"]when I add a new Form file with .cpp and .hpp file, Qt creator adds the following line in the .hpp file.
    @
    #if QT_VERSION >= 0x050000
    #include <QtWidgets/QDockWidget>
    #else
    #include <QtGui/QDockWidget>
    #endif
    @
    [/quote]What is your version of Qt Creator? (Help -> About Qt Creator...)

    Qt Creator 3.0.0 is the version needed for Qt 5.2, but it does not produce this code in UI headers.

    [quote]If I leave it that way my program crashes[/quote]Do you mean it compiles successfully and crashes when you run it? Or does it fail to compile?



  • bq. What is your version of Qt Creator? (Help -> About Qt Creator…)

    Qt Creator 3.0.0
    Based on Qt 5.2.0 (GCC 4.6.1, 64 bit)
    Built on Dec 10 2013 at 11:45:55
    From revision 27d10d8dcd

    bq. Do you mean it compiles successfully and crashes when you run it? Or does it fail to compile?

    It compiles successfully, but crashes on startup!


  • Moderators

    [quote]It compiles successfully, but crashes on startup![/quote]What is the error message? How did you run your program?



  • The application output is:
    Starting program
    The program has unexpectedly finished.
    program crashed

    I just hit Ctrl+R to run the program

    However I just added a view compile flags in CMakeLists.txt
    and it gives me now the warning that, QT_VERSION
    @#ifdef QT_VERSION > 0x050000@

    is not defined!


  • Moderators

    [quote author="chrislux" date="1390738513"]However I just added a view compile flags in CMakeLists.txt
    and it gives me now the warning that, QT_VERSION
    @#ifdef QT_VERSION > 0x050000@

    is not defined![/quote]It sounds like your CMake build system is broken. I'm not familiar with CMake, so I don't know how to fix it, sorry. Perhaps someone else can chime in.

    Your Qt installation itself might be fine. What happens if you create a new "Qt Widgets Application" and then run it? (Don't modify the code)

    [quote author="chrislux" date="1390738513"]The application output is:
    Starting program
    The program has unexpectedly finished.[/quote]That is a very generic message that means "your program crashed". To get more useful info, you usually need to run your program from a debugger.



  • bq. That is a very generic message that means “your program crashed”. To get more useful info, you usually need to run your program from a debugger.

    If I start the program with the build in debug tool from Qt Creator, it does not tell me much more.

    • During startup program terminated with signal SIGSEGV, Segmentation fault.

    bq. Your Qt installation itself might be fine. What happens if you create a new “Qt Widgets Application” and then run it? (Don’t modify the code)

    That's pretty interesting, I created a new project (no cmake) using Qt version 5.2, as usual Qt Creator added the
    @#if QT_VERSION >= 0x050000
    #include <QtWidgets/QMainWindow>
    #else
    #include <QtGui/QMainWindow>
    #endif@

    preprocessor statements. Again the first if statement isn't true.
    Maybe it has something to do with the system variables?


  • Moderators

    [quote author="chrislux" date="1390751578"]If I start the program with the build in debug tool from Qt Creator, it does not tell me much more.

    • During startup program terminated with signal SIGSEGV, Segmentation fault.[/quote]The debugger provides a stack trace which shows the file and line number where the crash occurred, as well as the stack of function calls that led up to the crash.
      [quote]That's pretty interesting, I created a new project (no cmake) using Qt version 5.2, as usual Qt Creator added the
      @#if QT_VERSION >= 0x050000
      #include <QtWidgets/QMainWindow>
      #else
      #include <QtGui/QMainWindow>
      #endif@

    preprocessor statements. Again the first if statement isn't true.
    Maybe it has something to do with the system variables?[/quote]I have the exact same version of Qt Creator as you in Ubuntu, but mine never generates these preprocessor statements -- Qt Creator adds the correct header depending on what version of Qt I'm compiling with. My Windows copy of Creator does the same. I'm very curious where these statements come from.

    It's really unnecessary: #include <QMainWindow> will work on both Qt 4 and Qt 5.

    Anyway,

    When you created the new project, did you get a .pro file?

    Which kit are you building with? (Mouse-over the little computer icon at the bottom-left of Creator. It should show your Project, Kit, Build, etc.

    Open Tools -> Options -> Build & Run -> Qt Versions, and click on the version you see in (1). Expand "Details" next to "Qt version". Can you post the values listed there? (Name, ABI, Source, QT_INSTALL_*, QT_VERSION, etc.)



  • bq. The debugger provides a stack trace which shows the file and line number where the crash occurred, as well as the stack of function calls that led up to the crash.

    Well the problem is cmake, because when I try to compile the project with qmake (using .pro files) instead of cmake, I'll get compile errors
    @ undefined reference to QWidget......@

    But when I compile the project with cmake I don't get a compile error!
    The only warning it shows is that QT_VERSION is not defined!
    Here is the stack-trace after SIGSEGV

    @0 ??
    1 ?? /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Gui.so.5 0x7ffff71db8bc
    2 QPainter::begin(QPaintDevice*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Gui.so.5 0x7ffff71dbea5
    3 QDockWidget::paintEvent(QPaintEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff7a27038
    4 QWidget::event(QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff7930e41
    5 QDockWidget::event(QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff7a2906b
    6 QApplicationPrivate::notify_helper(QObject*, QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff78f8f34
    7 QApplication::notify(QObject*, QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff78fc50e
    8 QCoreApplication::notifyInternal(QObject*, QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Core.so.5 0x7ffff6ad0554
    9 ?? /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff792da2b
    10 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff792e774
    11 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff792e50f
    12 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff792e50f
    13 ?? /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff792d82e
    14 ?? /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff7905409
    15 ?? /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff7905569
    16 ?? /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff7952a18
    17 QApplicationPrivate::notify_helper(QObject*, QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff78f8f34
    18 QApplication::notify(QObject*, QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Widgets.so.5 0x7ffff78fc50e
    19 QCoreApplication::notifyInternal(QObject*, QEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Core.so.5 0x7ffff6ad0554
    20 QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Gui.so.5 0x7ffff6ff5d25
    21 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Gui.so.5 0x7ffff6ffe275
    22 QWindowSystemInterface::sendWindowSystemEvents(QFlagsQEventLoop::ProcessEventsFlag) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Gui.so.5 0x7ffff6fe5ae8
    23 ?? /opt/Qt5.2.0/5.2.0/gcc_64/plugins/platforms/libqxcb.so 0x7fffeb424fd0
    24 g_main_context_dispatch /lib64/libglib-2.0.so.0 0x381b6492a6
    25 g_main_context_iterate.isra.24 /lib64/libglib-2.0.so.0 0x381b649628
    26 g_main_context_iteration /lib64/libglib-2.0.so.0 0x381b6496dc
    27 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Core.so.5 0x7ffff6b20fc4
    28 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Core.so.5 0x7ffff6acf2cb
    29 QCoreApplication::exec() /opt/Qt5.2.0/5.2.0/gcc_64/lib/libQt5Core.so.5 0x7ffff6ad333e
    30 main main.cpp 19 0x4298d0@

    bq. When you created the new project, did you get a .pro file?

    Yes!

    @QT += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = test
    TEMPLATE = app
    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui@

    bq. Which kit are you building with? (Mouse-over the little computer icon at the bottom-left of Creator. It should show your Project, Kit, Build, etc.

    Kit: Desktop Qt 5.2.0 GCC 64 bit

    bq. Open Tools -> Options -> Build & Run -> Qt Versions, and click on the version you see in (1). Expand “Details” next to “Qt version”. Can you post the values listed there? (Name, ABI, Source, QT_INSTALL_*, QT_VERSION, etc.)
    @Name: Qt 5.2.0 GCC 64bit
    ABI: x86-linux-generic-elf-64bit
    Source: /opt/Qt5.2.0/5.2.0/gcc_64
    mkspec: linux-g++
    qmake: /opt/Qt5.2.0/5.2.0/gcc_64/bin/qmake
    Version: 5.2.0
    QMAKE_SPEC linux-g++
    QMAKE_VERSION 3.0
    QMAKE_XSPEC linux-g++
    QT_HOST_BINS /opt/Qt5.2.0/5.2.0/gcc_64/bin
    QT_HOST_DATA /opt/Qt5.2.0/5.2.0/gcc_64
    QT_HOST_LIBS /opt/Qt5.2.0/5.2.0/gcc_64/lib
    QT_HOST_PREFIX /opt/Qt5.2.0/5.2.0/gcc_64
    QT_INSTALL_ARCHDATA /opt/Qt5.2.0/5.2.0/gcc_64
    QT_INSTALL_BINS /opt/Qt5.2.0/5.2.0/gcc_64/bin
    QT_INSTALL_CONFIGURATION /etc/xdg
    QT_INSTALL_DATA /opt/Qt5.2.0/5.2.0/gcc_64/
    QT_INSTALL_DEMOS /opt/Qt5.2.0/5.2.0/gcc_64/examples
    QT_INSTALL_DOCS /opt/Qt5.2.0/5.2.0/gcc_64/doc
    QT_INSTALL_EXAMPLES /opt/Qt5.2.0/5.2.0/gcc_64/examples
    QT_INSTALL_HEADERS /opt/Qt5.2.0/5.2.0/gcc_64/include
    QT_INSTALL_IMPORTS /opt/Qt5.2.0/5.2.0/gcc_64/imports
    QT_INSTALL_LIBEXECS /opt/Qt5.2.0/5.2.0/gcc_64/libexec
    QT_INSTALL_LIBS /opt/Qt5.2.0/5.2.0/gcc_64/lib
    QT_INSTALL_PLUGINS /opt/Qt5.2.0/5.2.0/gcc_64/plugins
    QT_INSTALL_PREFIX /opt/Qt5.2.0/5.2.0/gcc_64
    QT_INSTALL_QML /opt/Qt5.2.0/5.2.0/gcc_64/qml
    QT_INSTALL_TESTS /opt/Qt5.2.0/5.2.0/gcc_64/tests
    QT_INSTALL_TRANSLATIONS /opt/Qt5.2.0/5.2.0/gcc_64/translations
    QT_SYSROOT
    QT_VERSION 5.2.0
    @



  • I know now why Qt Creator is adding this statement, there is a checkbox under Settings->Designer->Class Generation
    In the groupbox Code Generation the checkbox ( Add Qt Version #ifdef for module names) was checked.

    But it still adds the wrong include of QMainWindow!
    Should be:
    @#include <QtWidgets/QMainWindow>@

    when using Qt version > 5
    Instead of:
    @#include <QtGui/QMainWindow>@


Log in to reply
 

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