0
votes

I'm new to Qt and have just installed the latest version of Linux (mint Ubuntu 13.04) to begin my programming. To begin with I have installed Qt4 using the github BuildScript (this also installs QtCreater, QtDesigner, QtAssistant, and QtLinguist). I have also installed PySide, as I plan to do a little Python gui programming as well. I did not consciously install qt5, but it appears, at some point along the line I did.

The following program from the QT tutorial illustrates my issue:

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello Qt!");
    label->show();
    delete label;
    return app.exec();
}

Now running:

..] $ qmake -project
..] $ qmake
..] $ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB
    -DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I.
    -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.
    -o helloWorld.o helloWorld.cpp helloWorld.cpp:1:24:
fatal error: QApplication: No such file or directory compilation terminated.

which obviously means gcc isn't finding QApplications in the libraries specified by qmake. Investigating this:

..] $ sudo find / -name QApplication*  
/usr/include/qt4/QtGui/QApplication
/usr/include/qt5/QtWidgets/QApplication
/home/drk/Canopy/appdata/canopy-1.0.1.1189.rh5-x86_64/include/QtGui/QApplication

Looking in the make file, the libraries supplied are (as can be seen from the compiler line):

INCPATH = -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5
          -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.

Finally, looking at qmake:

..] $ qmake --version
QMake version 3.0
Using Qt version 5.0.1 in /usr/lib/x86_64-linux-gnu

So as you can see, qmake is assuming qt 5.0.1 despite the fact that I installed Qt4 and in my qt5 library directory hierarchy "QApplications" is located in /usr/include/qt5/QtWidgets and not in QtGui. However, qmake does not add QtWidgets/ to my include libraries.

I don't understand what has happened...can one not have qt4 and qt5 on one system at the same time?...does my qt5/qt5 installation appear corrupted?...how do I get qmake to use Qt4? Any suggestions would be greatly appreciated.

2
Is there any particular reason you are creating and deleting the QLabel without even reaching the event loop?dtech
yes, stupidity! ... thank you for preempting my bug!dmon

2 Answers

3
votes

You can have both Qt 4 and 5 on the same system. However, there are little differences amongst them, and you're hitting one of those. In Qt 5, widgets now live in their own module, so you need to add

QT += widgets

to your .pro file and rerun qmake.

(And before you say that you don't see anything on screen: do not delete the label!)

1
votes

See if there's a "qmake4", "qt4-qmake" or "qmake-qt4" command instead of just "qmake".

Also, why did you install Qt4 externally? Ubuntu offers it in its repositories. Just install it with Ubuntu's package manager. This way you can be sure it will be installed correctly. Qt Creator is also available in the repos.