qt5 can't find widgets includes

  • Hi,
    I've tried setting up Qt in a number of different ways and haven't gotten it working so far. I tried compiling from source with msys on windows 10 but I had a lot of difficulties. First, the srcbase didn't equal the outbase so I went into qtbase/bin/syncqt.pl and added $srcbase = $outbase several places, and then deleted all the header files in, I think include/QtCore.

    Then I got a bunch of "has not been declared" errors from
    c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\cstdlib:201:11: error: '::lldiv_t' has not been declared
    using ::lldiv_t;
    I think this is because c:\mingw\include isn't in the path somehow, but I don't know how to get it in the path. I tried adding -Ic:\mingw\include to the configure options but it didn't work. Note that I can compile a test file with #include <algorithm> fine.

    Then I gave up on compiling from source and used the installer. I also installed Qt on a gentoo setup, and then compiling a project can't find the widget include files. Both windows 10 from the installer with qtcreator or mingw, as well as the gentoo setup give errors like these on trying to compile a project:

    g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++0x -Wall -Wextra -frtti -fexceptions -mthreads -DUNICODE -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I. -Inetwork -Iaudio -Igtp -Igame_interfaces -Igame_tree -Iboard -Isgf -IC:/Qt/5.6/mingw49_32/include -IC:/Qt/5.6/mingw49_32/include/QtMultimedia -IC:/Qt/5.6/mingw49_32/include/QtWidgets -IC:/Qt/5.6/mingw49_32/include/QtGui -IC:/Qt/5.6/mingw49_32/include/QtANGLE -IC:/Qt/5.6/mingw49_32/include/QtNetwork -IC:/Qt/5.6/mingw49_32/include/QtCore -Idebug -I. -IC:/Qt/5.6/mingw49_32/mkspecs/win32-g++ -o objects/displayboard.o displayboard.cpp
    In file included from displayboard.h:26:0,
    from displayboard.cpp:23:
    board/board.h:40:1: error: expected class-name before '{' token
    board/board.h:44:27: error: 'QGraphicsScene' has not been declared
    Board(QWidget *parent=0, QGraphicsScene *c=0 );

    Any help is appreciated, thanks.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you add QT += widgets to your .pro file ?

    Since Qt 5., the widgets have their own module.

    If you need to update your .pro file, don't forget to re-run qmake before building your project.

    On a side note, if you want to build Qt on Windows with MinGW, you should rather use the version provided with the installer.

  • Sure enough, most of the trouble was qt5/qt4 stuff. I'm using this all over the place:
    #if QT_VERSION >= 0x050000
    #include <QtWidgets>

    As for compiling qt, I was trying to compile from the git repositories.

    A last question, where are the QtCore.dll, etc., supposed to be? I ended up copying them into the application directory but that doesn't feel right.

  • Lifetime Qt Champion

    That's a nasty hack, you are using a module includes which means that you are pulling in every header of that module.

    The correct way is to drop the module part of the includes i.e. #include <QtGui/QWidget> becomes #include <QWidget>.

    Then adding QT += widgets to your .pro file will be enough.

    If you try to run your application from the explorer then you have to follow the deployment guide.

Log in to reply

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