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. Problem with modelData. QVarient questions.
Forum Updated to NodeBB v4.3 + New Features

Problem with modelData. QVarient questions.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 469 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by Circuits
    #1

    I want to start off by apologizing if this questions seems vague. It is that way because I am confused and don't know what's going on.

    My question is regarding a variable I am working with called modelData. In this application (I did not build) there is a portion of code which confuses me:

    Component.onCompleted:
      {
        ...
        else if(typeof(modelData.value) === "string" && modelData.optionsList.length === 0)
        {
          modelData.settingInvalid ? value_container.allowNext = false : value_container.allowNext = true
          ldr.sourceComponent = textEntryComponent
          value_container.objectName = "textbox"
        }
        else if(typeof(modelData.value) === "number" && modelData.optionsList.length !== 0)
        {
          ldr.sourceComponent = listOptionComponent
          value_container.objectName = "list"
        }
    ....
    

    How is it possible for this modelData's value to be either a string or a number? Does that mean I am dealing with two different variables both called modelData or is it possible that this variable is changing it's initialization on the back-end somehow?

    JonBJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      What language is this code in?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply
      0
      • VRoninV VRonin

        What language is this code in?

        C Offline
        C Offline
        Circuits
        wrote on last edited by
        #3

        @VRonin The code shown is QML but the code on the back-end is all C++.

        1 Reply Last reply
        0
        • C Circuits

          I want to start off by apologizing if this questions seems vague. It is that way because I am confused and don't know what's going on.

          My question is regarding a variable I am working with called modelData. In this application (I did not build) there is a portion of code which confuses me:

          Component.onCompleted:
            {
              ...
              else if(typeof(modelData.value) === "string" && modelData.optionsList.length === 0)
              {
                modelData.settingInvalid ? value_container.allowNext = false : value_container.allowNext = true
                ldr.sourceComponent = textEntryComponent
                value_container.objectName = "textbox"
              }
              else if(typeof(modelData.value) === "number" && modelData.optionsList.length !== 0)
              {
                ldr.sourceComponent = listOptionComponent
                value_container.objectName = "list"
              }
          ....
          

          How is it possible for this modelData's value to be either a string or a number? Does that mean I am dealing with two different variables both called modelData or is it possible that this variable is changing it's initialization on the back-end somehow?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Circuits said in Problem with modelData. QVarient questions.:

          How is it possible for this modelData's value to be either a string or a number?

          Why shouldn't it be? Also, this code looks like it's supplying generic code: modelData is some data value from the model, it might come from any row and column, so the code says if it's a string do this and if it's a number do that.

          Code is JavaScript, which is an untyped language. Unlike, say, C++, modelData can hold any value type, it never gets pre-declared as str or int or anything. If anything, think of it as a QVariant, kind of.

          C 1 Reply Last reply
          0
          • JonBJ JonB

            @Circuits said in Problem with modelData. QVarient questions.:

            How is it possible for this modelData's value to be either a string or a number?

            Why shouldn't it be? Also, this code looks like it's supplying generic code: modelData is some data value from the model, it might come from any row and column, so the code says if it's a string do this and if it's a number do that.

            Code is JavaScript, which is an untyped language. Unlike, say, C++, modelData can hold any value type, it never gets pre-declared as str or int or anything. If anything, think of it as a QVariant, kind of.

            C Offline
            C Offline
            Circuits
            wrote on last edited by
            #5

            @JonB OH ic, so your saying the type is probably being determined on the front end? In other words, somewhere (prior to this code) it's value is being specified to be either an int or a string or what-have-you. Is that what your saying?

            JonBJ 1 Reply Last reply
            0
            • C Circuits

              @JonB OH ic, so your saying the type is probably being determined on the front end? In other words, somewhere (prior to this code) it's value is being specified to be either an int or a string or what-have-you. Is that what your saying?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Circuits
              I suppose the short answer is yes, though its rather determined in the backend of code, which means not in the UI.

              The data presumably started life as some value in some row/column of something. That type may have been preserved, or it may have got converted all over the place, who knows.

              Actually the code tests modelData.value. JavaScript typeof() returns the type that is currently stored in modelData.value. At some point something set modelData.value = "a string" or modelData.value = 99 or modelData.value = -123.45 or whatever. It looks like the code then decides what kind component/widget would be suitable for displaying that type of value.

              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