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
Forum Updated to NodeBB v4.3 + New Features

How to save code in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 412 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.
  • A Offline
    A Offline
    ACaldas
    wrote on 30 Apr 2021, 00:01 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
    • J Offline
      J Offline
      jeremy_k
      wrote on 30 Apr 2021, 03:30 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 30 Apr 2021, 04:00
      1
      • 6 Offline
        6 Offline
        6thC
        wrote on 30 Apr 2021, 04:00 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
        • J jeremy_k
          30 Apr 2021, 03:30

          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 30 Apr 2021, 04:00 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.

          J 1 Reply Last reply 30 Apr 2021, 05:25
          0
          • A ACaldas
            30 Apr 2021, 04:00

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

            J Offline
            J Offline
            jeremy_k
            wrote on 30 Apr 2021, 05:25 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

            1/5

            30 Apr 2021, 00:01

            • Login

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