Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to save code in QML

How to save code in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 402 Views
  • 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.
  • A Offline
    A Offline
    ACaldas
    wrote on last edited by
    #1

    Hi all!

    I wonder if we could somehow save code in cases like this. Is it possible in a QML context?

    onToggled: {
                                        bc.checked = false
                                        bb.checked = false
                                        bd.checked = false
                                        spinBox1.enabled = false
                                        spinBox2.enabled = false
                                        spinBox3.enabled = false
                                        spinBox4.enabled = false
                                        spinBox5.enabled = false
                                        spinBox1.value = 0
                                        spinBox2.value = 0
                                        spinBox3.value = 0
                                        spinBox4.value = 0
                                        spinBox5.value = 0
                                    }
    

    Thanks for replying.

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      It's not clear to me what save means in this case. Is the goal to reduce the number of lines of code, write it to a file, write the values to a file, or something else?

      Asking a question about code? http://eel.is/iso-c++/testcase/

      A 1 Reply Last reply
      1
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by
        #3

        I persist data for: application, runtime mode & user preference's via both:

        • https://doc.qt.io/qt-5/qsettings.html
        • https://doc.qt.io/qt-5/qml-qt-labs-settings-settings.html

        I typically persist single values and rather not complex types or anything - just strings and numbers. But I do also persist QColor types as well.

        I use labs qml settings for user preferences and on windows it dumps that in the registry, which is good as I like to keep separated multiple QSettings files for application config and different application mode config files.

        1 Reply Last reply
        1
        • jeremy_kJ jeremy_k

          It's not clear to me what save means in this case. Is the goal to reduce the number of lines of code, write it to a file, write the values to a file, or something else?

          A Offline
          A Offline
          ACaldas
          wrote on last edited by
          #4

          @jeremy_k
          Exactly. There's so much lines for the same goal (to disable the instances spinBoxes).
          I thought that there should be a syntax in qml so that the action affects these five spinBox once instead of line by line.

          jeremy_kJ 1 Reply Last reply
          0
          • A ACaldas

            @jeremy_k
            Exactly. There's so much lines for the same goal (to disable the instances spinBoxes).
            I thought that there should be a syntax in qml so that the action affects these five spinBox once instead of line by line.

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by jeremy_k
            #5

            @ACaldas If they're all visual children of a container item, this imperative block works:

            onToggled: {
                for (var child in parentItem.children) {
                    if (undefined !== parentItem.children[child].checked) {
                        parentItem.children[child].checked = false;
                    }
                    else if (undefined !== parentItem.children[child].enabled) {
                        parentItem.children[child].enabled = false;
                        parentItem.children[child].value = 0;
                    }
                }
            }
            

            You might also look into either directly binding the values, or using a State. I don't think that these will result in fewer lines, but the relationships might be easier to understand and modify when necessary.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            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