How to manage subdirs examples (C/C++) ?
-
I am asking for a discussion / advises on the following :
I have a working Qt Creator "subdir" project and like to add specific example (sub project ) into it .The example was build using 5.15.x and works fine as an interdependent ".pro" project.
When added as "existing (sub) project" it fails since ONE of the classes used was introduced in 6.8.1.
( in fails to find required header file )
Forward declarations do not solve the issue...In shorts - I have a working subproject - created in 5.15.2 - and have a conflict adding subproject with class introduced in 6.8.1.
Would it help to post some code here ?
-
@tccc
I don't know much about subprojects. But if you have a piece of code/subproject which requires Qt 6.x surely you would either have to upgrade the rest of your code/projects to same Qt 6.x or make the subproject work as Qt 5.15, which would include it not using any Qt6 specific classes, if that can even be done? You won't be able to mix different Qt versions in an overall project. -
Thanks for the prompt reply. Much appreciated.
For unknown reason(s) , which is not that important to resolve for now, , I have received couple of dozens error messages basically confirming my suspicion. ( I could post at least the relevant part, if there is an interest.)
Here is one issue with " subprojects releases not matching " - when I initially started the project I had a choice to "select all kits" .
That would indicate that each sub project "make" COULD use different release.
( BTW - I have not found HOW to actually verify each sub project "make" )On the other hand - what is wrong with assumption that HIGHER release should INCLUDE / build on PREVIOUS releases.
Again - these are just opinions / speculations.... -
Hi,
Except that it's not how it works.
The usual idea behind a subproject based project is that you separate various aspects of your big project with it but not try to build each with different versions of Qt.Unless you are using classes/methods that have been obsoleted and possibly removed, yes you should be able to build a Qt 5 project with Qt 6 if you followed the deprecation notices and kept your code up to date.
-
update
I am unable to verify if the sub directories MUST be compiled using same "kit".
I am using "mdi" example as main, executable, subproject. Its "version" is 15.5.2 and so is my sub project (btscanner)
Its ONLY btscanner example is also in "examples 15.5.2 " and work fine as stand alone .pro.
BUT - it uses class introduced in 6.8.0 ! Hence there must be a way to identify HOW .pro project build using 15.5.2 (!) manages to USE class introduced in 6.8.0.BTW
the "btscanner" has this in device.h and#include <qbluetoothlocaldevice.h>
cannot be found when the btscanner.pro is added as subproject
I believe that is the missing link why the btscanner.pro is failing to compile when added to sub project.
This is part of "device.h header :
#include <qbluetoothlocaldevice.h>
#include <QDialog>
QT_FORWARD_DECLARE_CLASS(QBluetoothDeviceDiscoveryAgent)
QT_FORWARD_DECLARE_CLASS(QBluetoothDeviceInfo)QT_USE_NAMESPACE
There is no forward declaration for
QBluetoothLocalDevice -
@tccc said in How to manage subdirs examples (C/C++) ?:
BUT - it uses class introduced in 6.8.0 !
Which one?
As already stated: you can't mix different Qt versions in same application. -
@tccc said in How to manage subdirs examples (C/C++) ?:
BUT - it uses class introduced in 6.8.0 ! Hence there must be a way to identify HOW .pro project build using 15.5.2 (!) manages to USE class introduced in 6.8.0.
As I said earlier, you cannot mix Qt versions in one overall project.
If you understand C++/linking you would know that forward declarations can address a compile time issue but would leave you with a link-time error at linking since there is a declaration but no definition for the class.
As per previous you have two choices:- Rewrite the Qt6 sub-project code so that it compiles and links as Qt5. That would mean you will have to completely remove any class which does not exist in Qt 5. Get rid of any need for a Qt6-only class, write your own definition for that class using Qt5, or else if you need it and cannot write it you are stuck.
- Port the rest of your project/sub-projects to Qt6. Hopefully not too hard. Then you can use your new Qt6 sub-project in it.
-
Would it be acceptable to re-post the "update" ?
Upon further research I have found than the failing project ( all in 5.15 ) is actually part of subdir project,
and my guess is that that is why it worlds by itself but fails when added as subdir.
The "bluetooth.pro" "main" suproject actually consist of two more sub protects.All of them are still "only" in 5.15 - no Qt 6 at all