#include <QApplication> - verbose description please.
-
I have been "advised" not to worry about Qt terminology, however, I like to have a verbal explanation about this particular syntax.
I have read the doc and understand its purpose, no need for reference or repeat - I know how #include works.
.
Unfortunately in example I am using - also named "application" such term seems to be used to indicate both QApplication class and the name of the current project as "application".
I was actually trying to make a duplicate of "application" project, also changing its name, and it did not work as expected. -
@AnneRanch said in #include <QApplication> - verbose description please.:
and it did not work as expected.
And what should we do with this information? We need the exact error and the source code where the error occurs.
-
I'm not sure what the actual question is, but there's really not much to it. As you already said there's a class called
QApplication
, which is kinda the central class of a Qt based apps and there's an include for it. That's it. Just regular C++ stuff.
The fact that you have project called "application" is coincidental and there's no special meaning to that word in Qt. It can be anything.If you're having errors please post them, with as much info around it as possible, be it compiler, linker or qmake error, as it's kinda impossible to help without knowing what's wrong.
-
Fine, perhaps usage of "module" instead of class thru me.
I am using standard example "application" to build my own.
It is way to early, I hope, to have complier errors using "application" example.
Sorry,I have a follow up question on the "include ".
- What is the intent to have this entry in project file
QT += widgets
- After I successfully duplicate the "application" - where is a a logical place to "rename" it ?
While in editor I cannot access the project file - it is already open.
I can exit Qt and let OS rename project just fine.
3, For future reference - how do I set "gcc" - both compiler and linker to option verbose mode ?
Thanks
-
Hi
QT += widgets
means "add the Widget Module"
All Qt classes live in modules and the module to included is shown in the docs.
example
-
OK, so project needs "module" and so does "main" needs class QApplication to use such module.
Somewhat confusing and redundant.
And I am still missing where I instruct Qt to use these "modules".
I can guess it is built-in into example I am using, of course in future I like to start project from scratch. But that is in future...But so far this is all about GUI, which is fine , but how do I add application real functions? Say I want to process wireless data which is not just GUI.
So do I have to add "QT += xxx module to project and then"normal " C++ classes to "main"?
Adding classes is starlight with intellisense, but how abut "modules"?
Of course I am aware of "modules" list existence, -
Hi,
The Qt modules are simply the different libraries as well as their examples, documentation put under a topic. For example QtCore contains all the base building blocks. QtWidgets contain the widget related building blocks.
Then you have other modules like QtConnectivity which provides support for example for Bluetooth.
What happens when you add "QT += widgets" to your .pro file is that qmake will setup the necessary flags for the compiler to find the includes matching the widgets module as well as the linker flags to link your application to the corresponding library.
-
I think the term "module" makes it more confusing than it's worth, so let's make clear what it is.
A Qt module is really just a regular C++ library. It can be static or dynamic, just like any other library.The .pro file is a project file used by build tool qmake. qmake is like CMake or MSBuild - it manages the various settings of a project and creates build rules for build tool (make, nmake etc.) that invokes compiler, linker and any other tools of the build. Since qmake is a tool that was created specifically for the Qt library it has some functionalities that make using Qt easier. One of those functionalities is the mentioned
QT += xxx
syntax. All it really does is adds include and library paths to the compiler invocation. This is the same as providing them manually via compiler flags, it's just made easier for Qt libraries specifically.That being said you could if you wanted add all the libraries, Qt and non-Qt in the same way, it's just a lot more convenient this way and you also get extra benefits, like the fact that Qt Creator (the IDE) also understands this syntax and will for example have improved syntax suggestions.
So to summarize, you add non-Qt libraries this way:INCLUDEPATH += C:/something/include/ LIBS += -LC:/something/lib -lfilename
and for Qt libraries there's a shortcut:
QT += widgets
which will add the includes and library for the QtWidgets library.
-
As for all of this being about GUI - it's not. Qt has a lot of different libraries , only some of them are GUI related. By default qmake based projects add QtCore and QtGui libraries, so if you don't need GUI in your app you will have to remove QtGui library like this:
QT -= gui
.So do I have to add "QT += xxx module to project and then"normal " C++ classes to "main"?
So Qt modules are C++ libraries, and that's different from C++ classes. As in vanilla C++ you can either put a new class in the project of your executable or in another library. When you're using qmake in both cases there will be a .pro file for either that executable or that library. Assuming you have a class
MyClass
which has a headerMyClass.h
and implementation inMyClass.cpp
you add these to your chosen project .pro file like this:HEADERS += MyClass.h SOURCES += MyClass.cpp
Creating your own library is just creating another .pro file. The difference between an executable and a library is that executable has
TEMPLATE = app
and library hasTEMPLATE = lib
. Then you can create a top level .pro file (something like a "solution" in Visual Studio) that has some libraries and some executables linking together. The syntax for this is well documented so I won't go into details.To rename a project you simply close Qt Creator and rename that project's .pro file. That is different from the compiled executable name though, which is set inside the .pro file with
TARGET
, so if you want to change the name of the produced executable you change that. -
Going further - QApplication is class in Qt framework responsible for the basic inner workings of it. The most obvious one is dispatching events in an event loop. You mentioned you've used MFC before, so this is similar to message loop of that framework, just the syntax is different. Other things QApplication does is holds special state needed for thread management, governs application life cycle, holds application name, version etc, and a QGuiApplication variant of it has stuff like color palette and style class.
Since I'm on it, there are basically 3 variants of that application class. The basic one is
QCoreApplication
from the QtCore library, which you would use in a console app for example. From that derivesQGuiApplication
from the QtGui library and is intended for apps using GUI. The last one isQApplication
from the QtWidgets library and this is the one to go with if you want to use widgets in your GUI (as oppose to OpenGL, QML or something else). You choose one of these depending on what your app needs.When you have your application object chosen, you just initialize it with the command line params from
main()
and callexec()
on it, which starts an event loop, so similar to message dispatching loop in MFC. -
Last thing you asked I think was how to set compiler and linker to verbose. qmake has some options for common set of parameters across different compilers. For example you can use
CONFIG += c++17
to set a standard version used by the compiler and it will turn it into compiler specific options. For the complete list see here. I don't think there's one for the verbosity, but you can always pass compiler and linker specific options directly viaQMAKE_CXXFLAGS
andQMAKE_LFLAGS
, which is for compiler and linker respectively. If I'm not mistaken the verbose option in gcc is-v
, so it would beQMAKE_CXXFLAGS += -v
. -
Gentlemen,
you have no idea about the great value of all your posts.Now I have a better understanding about "strange - qmake (?) - Qt concepts".
It will take me some experimenting to navigate thru , but your comments make it much easier.
I was really disappointed by earlier "suggestion" not to worry about all this and find it odd why a very neat and usable tool like Qt, which I selected to provide access to GUI programming , is shrouded in generally undocumented terminology.
Years ago I tried OpenGL and after initial "discussions " here I was not sure if I should drop Qt and go back to OpenGLFor my "plain C++" development I use other IDE and appreciate very much NOT to have to deal with "make" on even irregular basis, optioning GCC is just that - no strange syntax , library is called library , class is class etc.
Yes, I can get used to Qt syntax, and terminology - NOW , after your posts,
thanks.