run through each components on the page

  • Hello,

    I would like to run through each components of a page. This will be in order to access a parameter of this element and get its state to save in a properties file to save some option.

    This is maybe not a good approach so if anybody know a good way to manage option on a saved file please tell me. It's the first time I have this kind of stuff in C++/QML.
    In Java it is made with ".properties" files. But I did not find any equivalent in C++/QML .

  • Moderators

    If it is only about saving settings, then you can use Settings component.

    If you do indeed want to run through all properties of all objects, do this:

    • get your root QML element in C++
    • loop (recursively) through all children
    • loop through all properties for each child

    A kind-of-but-not-really example for this can be found here

  • I'm taking a look at the Settings component.
    Is it capable to save the settings in separate file wich I could eventually generate with an external app. What it imply is that is as a well know format such as .xml, .json or something like that ?

  • Moderators

    @DavidM29 said in run through each components on the page:

    Is it capable to save the settings in separate file wich I could eventually generate with an external app

    Yes, see the docs:

    The information is stored in the system registry on Windows, and in XML preferences files on macOS. On other Unix systems, in the absence of a standard, INI text files are used. See QSettings documentation for more details.

    And this static method: QSettings::setPath().

  • Thank you for your replies.

    I think Settings is not the good solution for me because I haven't been able to find a way to have controls on when the parameters are saved on the file. I want them to change and save them only when a button is pressed. I already have file reading and writing functions in C++.
    My files are a bit like java ".properties" files :


    Regarding the loop on all my Qml element from C++ how can I access my QML component from a separate cpp file (I mean by that not from the main.cpp).

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.