[QML Runtime Tool - Qt 6.2] Using dummydata folder
-
Hi everybody,
I'm prototyping some UI QML files using qml runtime tool: regarding model data, I'd like using
dummydata
folder as used using old qmlscene tool.Using the same setup, if I'm using qmlscene, everything correctly works; using qml instead, dummy model data isn't load.
Using the comman
qml --help
, optionsdummydata
exists, however it seems not working as expected./usr/local/Qt-6.2.7/bin/qml --help Usage: /usr/local/Qt-6.2.7/bin/qml [options] [files...] [-- args...] Options: -h, --help Displays help on commandline options. --help-all Displays help including Qt specific options. -v, --version Displays version information. -a, --apptype <core|gui|widget> Select which application class to use. Default is gui. -I <path> Prepend the given path to the import paths. -f <file> Load the given file as a QML file. -c, --config <file> Load the given built-in configuration or configuration file. --list-conf List the built-in configurations. --translation <file> Load the given file as the translations file. --dummy-data <file> Load QML files from the given directory as context properties. --desktop Force use of desktop OpenGL (AA_UseDesktopOpenGL). --gles Force use of GLES (AA_UseOpenGLES). --software Force use of software rendering (AA_UseSoftwareOpenGL). --core-profile Force use of OpenGL Core Profile. --disable-context-sharing Disable the use of a shared GL context for QtQuick Windows --quiet Suppress all output. --verbose Print information about what qml is doing, like specific file URLs being loaded. --slow-animations Run all animations in slow motion. --fixed-animations Run animations off animation tick rather than wall time. -r, --rhi <backend> Set the backend for the Qt graphics abstraction (RHI). Backend is one of: default, vulkan, metal, d3d11, gl -S <selector> Add selector to the list of QQmlFileSelectors. Arguments: files Any number of QML files can be loaded. They will share the same engine. args Arguments after '--' are ignored, but passed through to the application.arguments variable in QML.
The folder structure used respects the following one:
project ├── Main.qml └── dummydata/ └── SampleModel.qml
where
SampleModel.qml
is the followingimport QtQuick ListModel { ListElement { name: "Prova 1" printingTimeS: 50 details: "Prova 1 description" } ListElement { name: "Prova 2" printingTimeS: 20 details: "Prova 2 description" } }
and
Main.qml
has the following piece of code:... ListView { anchors.fill: parent model: SampleModel delegate: Column { Text { text: "Nome: " + name } Text { text: "Tempo: " + printingTimeS + "s" } Text { text: "Dettagli: " + details } } } ...
I don't find anything on official Qt documentation regarding this aspect.
Any idea?
Thanks in advance,
Nicola -
Hi,
Just a shot in the dark based on the documentation of
qmlscene
but: try renaming your filesampleModel.qml
and apply the same logic in the code.@SGaist I try renaming
SampleModel.qml
tosampleModel.qml
, butqml
is not able to load dummy model.However, I find the solution watching qml tool source code.
Using Qt 6.2, the solution to load dummy-data is the following: supposing this folder structureproject ├── Main.qml └── dummydata/ └── SampleModel.qml
the steps are:
- set project folder as workdir (so, qml need to be execute within project path)
- execute the command
qml --dummy-data . Main.qml
Important note: since Qt 6.3, dummy-data options seems marked obsolete (from qml source code)
-
Hi,
Just a shot in the dark based on the documentation of
qmlscene
but: try renaming your filesampleModel.qml
and apply the same logic in the code. -
Hi,
Just a shot in the dark based on the documentation of
qmlscene
but: try renaming your filesampleModel.qml
and apply the same logic in the code.@SGaist I try renaming
SampleModel.qml
tosampleModel.qml
, butqml
is not able to load dummy model.However, I find the solution watching qml tool source code.
Using Qt 6.2, the solution to load dummy-data is the following: supposing this folder structureproject ├── Main.qml └── dummydata/ └── SampleModel.qml
the steps are:
- set project folder as workdir (so, qml need to be execute within project path)
- execute the command
qml --dummy-data . Main.qml
Important note: since Qt 6.3, dummy-data options seems marked obsolete (from qml source code)
-
-
Instead of using --dummy-data you could provide a module with a SampleModel singleton and use different import paths depending on if you want an actual model or a mock one.
-
Instead of using --dummy-data you could provide a module with a SampleModel singleton and use different import paths depending on if you want an actual model or a mock one.
@GrecKo that was the other idea.
But It means creating a QML module just for dummy model used for ui prototype; and I don't like to release that module on production code.
Example
Form.ui.qml
import com.myrealmodule import com.mydummymodule ... // Here I use singleton for dummy data ...
However if I don't release that dummy module, clearly I have runtime problem when application starts, cause it.s not able to find It.