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 get QML (5.15) to understand that when I declare a property to be an integer, I WANT it to be treated as an INTEGER, and NOT a FUNCTION!
Forum Update on Monday, May 27th 2025

How to get QML (5.15) to understand that when I declare a property to be an integer, I WANT it to be treated as an INTEGER, and NOT a FUNCTION!

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 387 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.
  • V Offline
    V Offline
    VFCraig
    wrote on last edited by
    #1

    QML 5.15

    I have a control. It allows a value to be incremented or decremented by a specified amount.
    The display can only hold up to 3 digits, so it must be less than 1000.

    The user can specify an adjustment value, adjustmentDelta, which defaults to 50.

    For those that need code to understand how that translates,

    property int adjustmentDelta: 50

    The minimum value is zero, the maximum is set to, (1000 - adjustmentDelta). Again, for those that require rudimentary code,

    property int theMinValue: 0
    property int theMaxValue: (1000 - adjustmentDelta)
    

    (And, honestly, give us a way to define LOCAL properties that are NOT visible outside the class WITHOUT creating a QtObject! Far too many hacks in QML to do basics.)

    When I attempt to test values to then show a message block that indicates if the minimum or maximum has been reached, it fails a simple boolean check, if (thValue >= theMaxValue), because it is treating, theMaxValue, as a function.

    The values have not changed within the module once theMaxValue was set. adjustmentDelta is still the same and 1000 is still the same. Even a function of such simplicity should return the same value consistently.

    Yes, I could write a ridiculously simple and wasteful function to return (1000 - adjustmentDelta) and assign theMaxValue to that return value, but again, just another way of hacking around QML.

    Once more, theMaxValue is a property defined as an integer. Let me use it as an INTEGER!

    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      Really didn't get your problem. The code below works fine:

          property int adjust: 50
          property int min: 0
          property int max: (1000 - adjust)
          property int current: 99942
      
          Button {
              anchors.centerIn: parent
              text: "Test"
              onClicked: {
                  console.log(adjust, min, max, current, current >= max)
                  console.log(typeof max)
              }
          }
      

      Output:

      qml: 50 0 950 99942 true
      qml: number
      
      1 Reply Last reply
      0
      • V Offline
        V Offline
        VFCraig
        wrote on last edited by
        #3

        Result from the following:

        print("\nHighPressureLimit: increase - (theValue => theMaxValue)="+(theValue => theMaxValue).toString()+", (theValue <= theMinValue)="+(theValue <= theMinValue).toString()+"\n")

        is,

        HighPressureLimit: increase - (theValue => theMaxValue)=function() { [native code] }, (theValue <= theMinValue)=false

        It's a BOOLEAN expression! Even if it contains a function, it should still result in true or false. (As the test of the min value obviously does.)

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by IntruderExcluder
          #4

          This is not an property feature, nor a QML feature. The same effects you can achieve with code below:

                      let variable;
                      console.log((variable => 42))
          

          This is how V4 engine and JavaScript works. But I think you just messed with syntax, cuz => isn't an comparison, it is new arrow function syntax. Just use >= instead, and there is no need to convert to string. E.g.:

          console.log("3 >= 5: " + (3 >= 5))
          
          1 Reply Last reply
          2
          • V Offline
            V Offline
            VFCraig
            wrote on last edited by
            #5

            The following...

            print("HighPressureLimit: increase - typeof theMaxValue = "+typeof theMaxValue+"\n")
            print("HighPressureLimit: increase - typeof theMinValue = "+typeof theMinValue+"\n")
            print("HighPressureLimit: increase - typeof theValue = "+typeof theValue+"\n")
            print("HighPressureLimit: increase - typeof (theValue => theMaxValue) = "+typeof (theValue => theMaxValue)+"\n")
            print("HighPressureLimit: increase - typeof (theValue <= theMinValue) = "+typeof (theValue <= theMinValue)+"\n")

            Results in...

            qml: HighPressureLimit: increase - typeof theMaxValue = number
            qml: HighPressureLimit: increase - typeof theMinValue = number
            qml: HighPressureLimit: increase - typeof theValue = number
            qml: HighPressureLimit: increase - typeof (theValue => theMaxValue) = function <- NOTE: This is NOT what I want.
            qml: HighPressureLimit: increase - typeof (theValue <= theMinValue) = boolean

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VFCraig
              wrote on last edited by
              #6

              The issue was => vs >=.

              Very frustrating. Would love to be creating this GUI in C++ instead.

              Thanks for the response, IntruderExcluder.

              1 Reply Last reply
              0
              • GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #7

                => isn't valid c++ either.

                1 Reply Last reply
                1

                • Login

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