Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Questions about QML
Forum Updated to NodeBB v4.3 + New Features

Questions about QML

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 554 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    "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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      For the C++ integration part, you should read:

      • Overview - QML and C++ Integration
      • Integrating QML and C++

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved