Regarding manual addition in .pro file for widgets
I used a bit of qt3 and qt4 but was trying to use qt5 for the first time. It seems now, as I learned from several websites, it is required to add the following line for many simple GI-based programs.
QT += widgets
I was wondering why is this so. I am using QMake version 3.0 and Qt version 5.0.2.
In Qt 4 and Qt 5, QMake automatically adds "QT += core" and "QT += gui" for you.
In Qt 4, widgets were part of the "GUI" module. But in Qt 5, widgets have been split off into a new "Widgets" module.
That means, in Qt 5, widgets are no longer automatically added by QMake.
Hi, welcome to devnet.
Qt5 was modularized to allow smaller deployments and easier development.
QtWidgets in particular was separated from general GUI module, so now you don't have to include it for example when you use only QtQuick or pure OpenGL windows.
A complete list of Qt5 modules is "here":http://qt-project.org/doc/qt-5.0/qtdoc/modules.html
Thanks JKSH and Chris Kawa for the patient replies.
My point is why does that statement need to be added manuallyif it can be automatically included by qmake. For instance it could be suggested to the users to have a statement such as below that could cause qmake to add the necessary statement in the .pro file.
I am unable to understand the necessity of having to do it explicitly to the project file sacrificing the user friendliness of Qt.
Because Qt now offers 3 major ways for creating GUIS:
- Low-level OpenGL
Not all GUIs use widgets, so not all projects need "QT += widgets".
In any case, if you tell Qt Creator to create a widget project, Qt Creator DOES add "QT += widgets" for you.
Thanks JKSH. I was writing the code manually so I think I ran into trouble. :)
You're welcome :)
[quote author="sinedie" date="1375624145"]...have a statement such as below that could cause qmake to add the necessary statement in the .pro file.
[/quote]I just re-read your suggestion, and think I understand your point better now.
Actually, it's the other way round: qmake reads "QT += widgets" first, and THEN generates the Makefile that tells your compiler where to find the <QtWidgets> header
I was talking of generating the .pro file as follows:
sh$ qmake -project
<manually edit the .pro file generated>
The manual editing could perhaps be avoided. I already see a problem here though, if widgets are not required in the initial pass it could be a mess. Could that be the only reason?
QT += is basically doing INCLUDEPATH += and a LIBS +=.
I guess it's a mater of opinion but I personally don't like when something is adding paths or links libraries in my project without me telling it to. I would go as far as to stop qmake from always adding the core module so I wouldn't have to write Qt -= core in non-Qt qmake projects.
The thing you propose - automatic linking libraries based on include statements - while possible, this would be difficult (and posssibly slow on large projects?) to get right. And what if you only wanted some enum definition and by including single header you got linker to throw in a whole module or bunch of them? Nah, sounds nasty to me...
I concur. :)