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. QML receives a C++ object
Forum Updated to NodeBB v4.3 + New Features

QML receives a C++ object

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

    Hi all,
    in my application I have a QML front-end where the user types a code.
    This code is checked against a list of values read on a database using C++ code.
    Now I'm able to recall the Q_INVOKABLE C++ function to query the database.
    The function returns an object containing the result and QML code should check the data and decide how to go on.
    I'm not able to use this object.

    var r = ds.checkCode( TipoPrenotazione.TIPO_RITIRO, edtCodicePrenotazione.text)
    console.log("ret: "+r)
    if (r===null)
             txtMsg.text = "Prenotazione not found"
    else {
             console.log("Trovata!", r)
             txtMsg.text = "Prenotazione found !"
             console.log(r._cassetto) //??
    }
    

    In the debug window I see:

    [DataSource] p: Prenotazione(0x8098b118)
    qml: ret: Prenotazione(0x8098b118)
    qml: Trovata! Prenotazione(0x8098b118)
    qml: undefined
    

    So the object is correct but how to access it ?

    I'm wondering if this flow is correct ...
    Thanks

    sierdzioS raven-worxR 2 Replies Last reply
    0
    • SteMMoS SteMMo

      Hi all,
      in my application I have a QML front-end where the user types a code.
      This code is checked against a list of values read on a database using C++ code.
      Now I'm able to recall the Q_INVOKABLE C++ function to query the database.
      The function returns an object containing the result and QML code should check the data and decide how to go on.
      I'm not able to use this object.

      var r = ds.checkCode( TipoPrenotazione.TIPO_RITIRO, edtCodicePrenotazione.text)
      console.log("ret: "+r)
      if (r===null)
               txtMsg.text = "Prenotazione not found"
      else {
               console.log("Trovata!", r)
               txtMsg.text = "Prenotazione found !"
               console.log(r._cassetto) //??
      }
      

      In the debug window I see:

      [DataSource] p: Prenotazione(0x8098b118)
      qml: ret: Prenotazione(0x8098b118)
      qml: Trovata! Prenotazione(0x8098b118)
      qml: undefined
      

      So the object is correct but how to access it ?

      I'm wondering if this flow is correct ...
      Thanks

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @SteMMo said in QML receives a C++ object:

      So the object is correct but how to access it ?

      Is _cassetto a Q_PROPERTY? You can only access Q_INVOKABLE methods and Q_PROPERTY values from QML.

      (Z(:^

      SteMMoS 1 Reply Last reply
      2
      • SteMMoS SteMMo

        Hi all,
        in my application I have a QML front-end where the user types a code.
        This code is checked against a list of values read on a database using C++ code.
        Now I'm able to recall the Q_INVOKABLE C++ function to query the database.
        The function returns an object containing the result and QML code should check the data and decide how to go on.
        I'm not able to use this object.

        var r = ds.checkCode( TipoPrenotazione.TIPO_RITIRO, edtCodicePrenotazione.text)
        console.log("ret: "+r)
        if (r===null)
                 txtMsg.text = "Prenotazione not found"
        else {
                 console.log("Trovata!", r)
                 txtMsg.text = "Prenotazione found !"
                 console.log(r._cassetto) //??
        }
        

        In the debug window I see:

        [DataSource] p: Prenotazione(0x8098b118)
        qml: ret: Prenotazione(0x8098b118)
        qml: Trovata! Prenotazione(0x8098b118)
        qml: undefined
        

        So the object is correct but how to access it ?

        I'm wondering if this flow is correct ...
        Thanks

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @SteMMo said in QML receives a C++ object:

        console.log(r._cassetto) //??

        i am not sure if it also applies to properties of QObjects, but for QML defined properties the property name MUST begin with a lowercase letter:

        Property names must begin with a lower case letter and can only contain letters, numbers and underscores

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • sierdzioS sierdzio

          @SteMMo said in QML receives a C++ object:

          So the object is correct but how to access it ?

          Is _cassetto a Q_PROPERTY? You can only access Q_INVOKABLE methods and Q_PROPERTY values from QML.

          SteMMoS Offline
          SteMMoS Offline
          SteMMo
          wrote on last edited by
          #4

          @sierdzio
          yes it is.
          But the key is: when I wrote the QML code and I use the r object, I cannot see its members.
          My guess is that the QML editor is not able to know the type of the returned object and I cannot define the r variable as Prenotazione.
          The runtime pointer is correct but the code is not able to locate 'cassetto'.
          Now I defined it as:

          Q_PROPERTY(int cassetto MEMBER _cassetto READ cassetto)
          

          and added

          int cassetto() { return _cassetto; };
          

          thanks

          sierdzioS 1 Reply Last reply
          0
          • SteMMoS SteMMo

            @sierdzio
            yes it is.
            But the key is: when I wrote the QML code and I use the r object, I cannot see its members.
            My guess is that the QML editor is not able to know the type of the returned object and I cannot define the r variable as Prenotazione.
            The runtime pointer is correct but the code is not able to locate 'cassetto'.
            Now I defined it as:

            Q_PROPERTY(int cassetto MEMBER _cassetto READ cassetto)
            

            and added

            int cassetto() { return _cassetto; };
            

            thanks

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5
            Q_PROPERTY(int cassetto MEMBER _cassetto READ cassetto)
                           ^ this is your property name
            

            It does not matter how your member variable is named, do not use it in QML! What QML sees is the property name (first string after type in Q_PROPERTY invokation).

            (Z(:^

            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