[Interest] qt_add_qml_module() RESOURCES vs qt_add_resources()

ekke ekke at ekkes-corner.org
Sun Feb 18 14:04:11 CET 2024


Am 16.02.24 um 21:06 schrieb Ulf Hermann via Interest:
> Hi Ekke,
>
> ...
> This is why it's generally a good idea to make the implicit import the 
> same as the module a component belongs to.
>
> I have understood, though, that nobody wants to follow this rule. I'll 
> come up with some technical solution that allows you to declare either 
> a module spanning multiple directories or a collection of modules, 
> each with its own directory. with a single CMake function call. The 
> earliest possible version for that to surface in is 6.8, though.
>
> best regards,
> Ulf

Hi Ulf,

thanks taking the time and explaining. Probably my problem is, that (in 
my Qt 5.15 projects) I never thought about "Modules".

I simply grouped my qml files and put similar ones into directories.

Would be great to get a technical solution to span multi directories in 6.8

BTW: perhaps I have overlooked it, but I never found a warning in all 
the blogs and docs, that qml files organized in directories will be 
problematic if used in Qt 6 QML Modules. Also didn't found recipes HowTo 
use in-directories-grouped-qml-files with qt_add_qml_module.

I'm a single independent mobile business app developer and I have to 
support up to 20 apps I ported from 5.15 to 6.6. Some of the apps are 
very complex and grown over 6+ years from the first days of QQC2 - beta. 
With help from JP Nurmi and Mitch Curtis I got the first apps running - 
development before was BB10 Cascades/Qt 4.8. My customers love the apps 
and I love Qt. Porting my apps from 5.15 to 6.6 was much more work as 
expected - took 9 months. https://t1p.de/ekkeChecklist  From my feeling 
it was harder as Cascades/4.8 ->5.0 ;-)

I got all my projects compile and run with 6.6 and QMake. Still some 
5.15 projects I cannot deliver  because of blocking bugs :(

Now I'm working on QMake -> CMake - again much work. Android apps nearly 
ready, iOS apps work-in-progress. Unfortunately ATM there's no doc about 
Qt-recommended-way-to-use-cmake-for-android-ios-apps to compile, build, 
deploy to device and GooglePlay/AppStore.

Back to CMake and qt_add_qml_module:

Porting 20 apps I have to go step-by-step and the first step is getting 
the apps compile and run with CMake.

The only way seems to be to load from URL instead from Module and to 
deal with the foot gun using RESOURCE_PREFIX and NO_RESOURCE_TARGET_PATH:

engine.load(QUrl(QStringLiteral("qrc:/qml/Main.qml")));

qt_add_executable(${MY_APP}
     cpp/main.cpp
)
qt_add_qml_module(${MY_APP}
     URI Main_Module
     QML_FILES
         ${my_qml_files}
     SOURCES
         ${my_cpp_files}
     RESOURCE_PREFIX /
     NO_RESOURCE_TARGET_PATH
     RESOURCES
         ${my_image_files}
         ${my_data-assets_files}
)

in my code now still is working:

import "../popups" etc

Loader ... source "../pages/ThePage.qml"

qrc:/images/...

As soon as all Apps are running on Android and iOS, I'll take the next 
step to remove/refactor from cpp code some

context->setContextProperty(...)

and also from all my QObject* Entities/DTOs:

qmlRegisterType(...)

Then I'll have much work in QML files to refactor hundreds of QML 
Connections()-syntax and also uncount missing id's...

Never have thought that the port from 5.15 to 6.6 would be so hard. I 
have to admit - there were days when I thought about whether Flutter 
would be an easier way, but I like Qt so much ;-)

To better understand my project structure, see below a more detailed one 
together with some quanties from a medium sized app.

thx

ekke

QML:
there around 230 qml files

/qml/Main.qml
/qml/bt/   (only if app supports BT LE)
         BTSettingsGeneralScan.qml
         ... (15 qml files - BluetoothLE)
/qml/common/
         FloatingActionButton.qml
         ... (55 qml files)
/qml/navigation/
         ScheduleNavigation.qml
         ... (20 qml files)
/qml/pages/
         SchedulePlanListPage.qml
         ... (80 qml files)
/qml/photo/    (only if app uses QML Camera)
         CapturePhotoPage.qml
         ... (15 qml files)
/qml/popups/
         PopupMissionDone.qml
         ... (40 qml files)
/qml/tabs/
         TextTabBar.qml
         ... (5 qml files)

RESOURCES (images and data-assets):

there are 120 icons
     in black and white, 18px, 24px, 63px, 48px
     and 4 densities, so around 3.800 single files
/images/...
         add.png
         add at 2x.png
         add at 3x.png
         add at 4x.png

/data-assets/mySettingsData.json
             ...

TRANSLATIONS:
translations/xxx.ts
              xxx_de.ts
              xxx_en.ts









More information about the Interest mailing list