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. return Myclass to qml

return Myclass to qml

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 1.5k 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.
  • S Offline
    S Offline
    Samuel Costa
    wrote on last edited by
    #1

    what is the best practice to return MYClass that is created in a method?

    ODБOïO 1 Reply Last reply
    0
    • S Samuel Costa

      what is the best practice to return MYClass that is created in a method?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Samuel-Costa Hi,
      http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html
      http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

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

        While the links above are useful they only scratch the surface.
        Could you be more specific regarding what kind an object is MYClass? is it basically only data? is it a QObject?

        "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

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Samuel Costa
          wrote on last edited by
          #4

          But I'm filling the object in a function, so I want to return that same object and receive it in javacript / QML.
          But the object undergoes changes from the QML side after some calls to that function. In which I get the error: ASSERT: "! Create" in file ....

          This line can only be called in main.cpp
          ApplicationData data;
          view.rootContext () -> setContextProperty ("applicationData", & data);

          But my object was filled in function, so I can not use it.

          Example of my class:
          0_1543858491948_d60dd39d-aace-4456-aa69-a21054a138c7-image.png

          Help me

          VRoninV 1 Reply Last reply
          0
          • S Samuel Costa

            But I'm filling the object in a function, so I want to return that same object and receive it in javacript / QML.
            But the object undergoes changes from the QML side after some calls to that function. In which I get the error: ASSERT: "! Create" in file ....

            This line can only be called in main.cpp
            ApplicationData data;
            view.rootContext () -> setContextProperty ("applicationData", & data);

            But my object was filled in function, so I can not use it.

            Example of my class:
            0_1543858491948_d60dd39d-aace-4456-aa69-a21054a138c7-image.png

            Help me

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5

            @Samuel-Costa said in return Myclass to qml:

            But my object was filled in function

            Can you show us the function signature?

            "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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Samuel Costa
              wrote on last edited by
              #6

              This is my function :
              0_1543869715481_1bd8c4d5-aac7-44ac-8bf7-4243d46bce37-image.png

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

                it should work. Can you show us the QML? (text instead of images helps)

                "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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Samuel Costa
                  wrote on last edited by
                  #8

                  At this point I'm just printing the object:
                  console.log("Here...... " + awi_base.getAwiProp("id_fld_51" , uiContext.currentAwiLabelDesignCanvas.awi_Base_Compound))

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Samuel Costa
                    wrote on last edited by
                    #9

                    I added this line to my function:
                    QQmlEngine::setObjectOwnership(prop, QQmlEngine::CppOwnership);
                    and it worked

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Samuel Costa
                      wrote on last edited by
                      #10

                      Can I get the AWI_PROP object this way in QML / JavaScript ?

                      QML:
                           property AWI_PROP awi_prop_width
                           property AWI_PROP awi_prop_height

                      JavaScript:
                        onAwiBase_CompoundChanged: {
                               awi_prop_width = awiBase_Compound.getAwiProp ("id_fld_51")
                               awi_prop_height = awiBase_Compound.getAwiProp ("id_fld_52")
                      }

                      1 Reply Last reply
                      0

                      • Login

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