The dark side of .pro file
-
Sorry, certainly I am just a normal user, but it is the second time that initially obscure errors for the proper program compiling can be solved adding a quite magical (for me) line to the .pro file.
The first time, creating a widget in Qt5, even if the command "qmake -project" was launched, the .pro file was missing for the line QT+=widget
Now, trying to compile the "Surface Example" I spent a lot of time to find the problem of the broken compilation with the message /home/marco/Workspace/QtSource/feritoMetro/fermet.cpp:236: error: undefined reference to `QtDataVisualization::Q3DSurface::Q3DSurface(QSurfaceFormat const*, QWindow*)’
The solution is add QT*=datavisualization to the .pro file.
My question is, why those lines are not automatically added or al least suggested by qmake -project? -
Hi and welcome to devnet,
Because qmake does not do deep inspections of all the files of your project.
This would require processing each and every include which is not its job. You can add on the command line additional informations when running qmake -project.
-
Hi
Well those are all modules and its not for sure you would need them at all
so qmake -project could not either add all of them or none.
https://doc.qt.io/qt-5/qtmodules.htmlHowever, if you create the project via Creator, then the Widgets module is added if you select Default GUI project.
Also, the docs tells what module to add for a given class

-
Hi
Well those are all modules and its not for sure you would need them at all
so qmake -project could not either add all of them or none.
https://doc.qt.io/qt-5/qtmodules.htmlHowever, if you create the project via Creator, then the Widgets module is added if you select Default GUI project.
Also, the docs tells what module to add for a given class

@mrjj many thanks for your answer. You are right, one should always carefully read the whole documentation. Unfortunately very often one is searching for quick solutions to specific needs and jump directly to the example.
In any case I found the same issue by trying the compile the "Surface Example" among the ones offered in example section of QtCreator. At least in that case I expect that the .pro file was rightly composed; instead after some hours I gave up. -
One thing that is strange is why are you calling qmake -project when trying to build one of the examples since they already have .pro files ?
-
Sorry, certainly I am just a normal user, but it is the second time that initially obscure errors for the proper program compiling can be solved adding a quite magical (for me) line to the .pro file.
The first time, creating a widget in Qt5, even if the command "qmake -project" was launched, the .pro file was missing for the line QT+=widget
Now, trying to compile the "Surface Example" I spent a lot of time to find the problem of the broken compilation with the message /home/marco/Workspace/QtSource/feritoMetro/fermet.cpp:236: error: undefined reference to `QtDataVisualization::Q3DSurface::Q3DSurface(QSurfaceFormat const*, QWindow*)’
The solution is add QT*=datavisualization to the .pro file.
My question is, why those lines are not automatically added or al least suggested by qmake -project?Hi, and welcome!
@MMonty1960 said in The dark side of .pro file:
My question is, why those lines are not automatically added or al least suggested by qmake -project?
This is documented at https://doc.qt.io/qt-5/qmake-running.html : "Note: It is likely that the created file will need to be edited. For example, adding the QT variable to suit what modules are required for the project."
qmake -projectsimply adds your existing .h and .cpp files to a .pro file. It doesn't know which modules your project needs.On a related note, you probably never need to call
qmake -project. Ever.In any case I found the same issue by trying the compile the "Surface Example" among the ones offered in example section of QtCreator. At least in that case I expect that the .pro file was rightly composed
Do you mean https://doc.qt.io/qt-5/qtdatavisualization-surface-example.html ? The example already comes with a surface.pro file which was set up correctly; just use that.
However, if you ran
qmake -projectin the example folder, that means you erased the existing (correct) .pro file and replaced it with an incomplete one. You'll need to reinstall the Qt Data Visualization module to restore the surface.pro file.initially obscure errors for the proper program compiling can be solved adding a quite magical (for me) line to the .pro file.
No magic is involved; everything is perfectly logical and documented.
"undefined reference" means that your linker can't find a library (this is applies to all C++ projects, not just Qt). So, you need to make sure your tools can find the libraries. With .pro files, this involves telling qmake which modules you need:
QT += widgetsmeans "add the Qt Widgets module to the list of modules needed by our project".QT += datavisualizationmeans "add the Qt Data Visualization module to the list of modules needed by our project".
See a pattern?
Finally, see https://doc.qt.io/qt-5/qmake-language.html for the difference between
+=and*= -
One thing that is strange is why are you calling qmake -project when trying to build one of the examples since they already have .pro files ?
@SGaist It was just one of N trials I did to solve the problem
-
Can you provide a link to that example ?
-
@SGaist said in The dark side of .pro file:
Can you provide a link to that example ?
I believe it's https://doc.qt.io/qt-5/qtdatavisualization-surface-example.html. I just tested it with Qt 5.15.2 and the *.pro file works fine.
-
@SGaist said in The dark side of .pro file:
Can you provide a link to that example ?
I believe it's https://doc.qt.io/qt-5/qtdatavisualization-surface-example.html. I just tested it with Qt 5.15.2 and the *.pro file works fine.
-
@SGaist said in The dark side of .pro file:
Can you provide a link to that example ?
I believe it's https://doc.qt.io/qt-5/qtdatavisualization-surface-example.html. I just tested it with Qt 5.15.2 and the *.pro file works fine.
@JKSH I am using Manjaro linux 64 bit xfce. When I select the "Surface example" a window pops-up asking is I want "copy and open" or "keep project and open". If I select "keep project and open", as next step I have to push "configure project" (I select Qt 5.10.1). Then the generated pro file is:
android|ios|winrt {
error( "This example is not supported for android, ios, or winrt." )
}!include( ../examples.pri ) {
error( "Couldn't find the examples.pri file!" )
}SOURCES += main.cpp
surfacegraph.cppHEADERS += surfacegraph.h
QT += widgets
requires(qtConfig(combobox))RESOURCES += surface.qrc
OTHER_FILES += doc/src/*
doc/images/*Of course that is the end of the experience. The same happen in the other choice. Maybe there is some error in my linux distro.
-
So my idea was correct, you are missing the examples.pri file.
Don't you have the warning shown when building the project ?
-
I find the issue "/example.pri" only in the choice "copy and open". I solved by manually copying that file, but the pro file remained unchanged and one again the experience end
-
I find the issue "/example.pri" only in the choice "copy and open". I solved by manually copying that file, but the pro file remained unchanged and one again the experience end
@MMonty1960 said in The dark side of .pro file:
but the pro file remained unchanged and one again the experience end
The pro file should remain unchanged since it is correct.
What do you mean "the experience end"? What happens when you use Qt Creator to build and run the project?
-
@MMonty1960 said in The dark side of .pro file:
but the pro file remained unchanged and one again the experience end
The pro file should remain unchanged since it is correct.
What do you mean "the experience end"? What happens when you use Qt Creator to build and run the project?
@JKSH The pro file is not correct because is missing for QT+=datavisualization so compilation fails.
Now I know the solution, thus if I add manually that line the compilation runs correctly.
In any case I would like to thank both SGaist and JKSH because I learned a lot by your answers. Many thanks!!!! -
@MMonty1960 said in The dark side of .pro file:
The pro file is not correct because is missing for QT+=datavisualization so compilation fails.
As @SGaist already told you examples.pri contains more stuff. When you take a look into it you will notice a 'QT += datavisualization' line so the pro file is correct.
-
@JKSH The pro file is not correct because is missing for QT+=datavisualization so compilation fails.
Now I know the solution, thus if I add manually that line the compilation runs correctly.
In any case I would like to thank both SGaist and JKSH because I learned a lot by your answers. Many thanks!!!!@MMonty1960 said in The dark side of .pro file:
@JKSH The pro file is not correct because is missing for QT+=datavisualization so compilation fails.
The pro file is correct. You just need to make sure that examples.pri is in the folder above surfaces.pro so that
QT += datavisualizationis included viainclude(../examples.pri). You don't need to modify surfaces.pro.But anyway, you have highlighted a weakness in the way examples are loaded so I opened a bug report: https://bugreports.qt.io/browse/QTCREATORBUG-25191
-
@MMonty1960 said in The dark side of .pro file:
@JKSH The pro file is not correct because is missing for QT+=datavisualization so compilation fails.
The pro file is correct. You just need to make sure that examples.pri is in the folder above surfaces.pro so that
QT += datavisualizationis included viainclude(../examples.pri). You don't need to modify surfaces.pro.But anyway, you have highlighted a weakness in the way examples are loaded so I opened a bug report: https://bugreports.qt.io/browse/QTCREATORBUG-25191
@JKSH Of course I copied example.pri in the folder above surface.pro, but there is no effect on the pro file and compilation crashed. Maybe the reason is that the pro file is composed before I applied the correction and after that is not more refreshed. In any case I failed to compile and run the example.
-
@JKSH Of course I copied example.pri in the folder above surface.pro, but there is no effect on the pro file and compilation crashed. Maybe the reason is that the pro file is composed before I applied the correction and after that is not more refreshed. In any case I failed to compile and run the example.
@MMonty1960 said in The dark side of .pro file:
Maybe the reason is that the pro file is composed before I applied the correction and after that is not more refreshed.
Yes, you're right. You can force a refresh by clicking Build > Run qmake. That should let you compile and run the example.