Questions about QML
-
"Most people know that each element in a QML file is backed by a C++ class. When a QML file is loaded, the QML engine somehow creates one C++ object for all elements in the file."-QML Engine Internals, Part 1: QML File Loading
Could someone please explain to me what exactly is meant by "element"? Also, I can not figure out how most of the QML scripts are being loaded into this application I am working on (learning QT by working on). Sometimes it is obvious:
onShowKeyboard: { var comp = Qt.createComponent("qrc:/Source/QML/UiControls/WizardPopupKeyboard.qml"); comp.createObject(application, { "title": mod_data.label ,"objectName":"systemDialog" , "hint": qsTr("Enter a value between %1 and %2").arg(Math.round(mod_data.minValue)).arg(Math.round(mod_data.maxValue)) , "modelButtons": [qsTr("Cancel"), qsTr("Finished")] , "primaryIndex": 1 , "controlTarget": minMaxSplitBtn , "settingValue": mod_data }) }
however; most of the .qml scripts in this project do not seem to be loaded into the application from the C++ scripts. I am new to Qt and QML but I thought the general idea was to load .qml scripts from within your C++ code for instance:
int main(int argc, char *agrv[]) { QGuiApplication app(argc, argv); QQuickView viewer; ...stuff... viewer.setSource(QUrl("qrc/script.qml")); ...stuff... return app.exec(); }
If I try a grep search for WizardSectionDisplay.qml (one of the QML files I am working on) in the CodeBase containing this project here are my results:
rob@linux044:~/Sandbox/trunk/CodeBase$ grep -lr WizardSectionDisplay.qml * Apps/common/Ui/Source/QML/UiControls/qmldir Apps/common/Makefile Apps/common/QML.qrc Apps/common/qrc_QML.cpp
I assumed the first two results were erroneous but I figured the last two might have something to do with it. So I tried looking for QML.qrc and qrc_QML.cpp from within Qt Creator. I found that QML.qrc is just the name of a file within the Resources directory. I actually was not able to find qrc_QML.cpp from within Qt Creator at all. So instead I opened the file in CodeBlocks and I found arrays of data with a bit of logic at the end of the file which I can't make heads or tails of. Is this what the quote above was talking about when it said: "...a QML file is loaded, the QML engine somehow creates one C++ object for all elements in the file."
The reason I am asking is because this script (WizardSectionDisplay.qml) makes use of a variable called modelData. I would like to learn more about how modelData works, how models work and how QML communicates with C++ files when they aren't being loaded directly in the C++ code.
-
Hi,
For the C++ integration part, you should read:
What elements does WizardSectionDisplay.qml use ?
QtQuick is a declarative language, the items mentioned there are the one you declare in your .qml files. They can come from libraries like the one you are using as building blocks for for example your WizardSectionDisplay.
The .qrc file is part of the Qt Resources System. It it used to generate C++ code that will embedded the files linked by that file inside your application executable.