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 property assign is after the C++ constructor??
QtWS25 Last Chance

QML property assign is after the C++ constructor??

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 5.1k 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.
  • H Offline
    H Offline
    harlentan
    wrote on last edited by
    #1

    Hi,
    Creating a object in QML using c++ class, does the property binding and assign happen after the C++ constructor?
    @
    class MyClass: public QObject
    {
    //...
    Q_PROPERTY(QString name READ GetName WRITE SetName)

    Public:
    MyClass(){
    //...I must use the name in the constructor, But failed , the property name is assigned after the constructor.
    }

    }

    //QML file

    MyClass{
    name: "Harlen"
    }
    @

    the name: "Harlen" assign happens after the C++ Constructor.

    :)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #2

      Yes, for your answer

      Chuck

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chuck Gao
        wrote on last edited by
        #3

        And i know who are you right now. :-)

        Chuck

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          Hi,

          I'm not sure if it will be useful in your case, but "QDeclarativeParserStatus":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeparserstatus.html will let you know when all properties have been set on the object, if you need to e.g. delay certain actions until that happens.

          Regards,
          Michael

          1 Reply Last reply
          0
          • H Offline
            H Offline
            harlentan
            wrote on last edited by
            #5

            [quote author="Chuck Gao" date="1314073810"]And i know who are you right now. :-)[/quote]

            :) Me too.
            The first time I posted here in the Qt Forum, I saw you in many replies

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chuck Gao
              wrote on last edited by
              #6

              有一种办法是,你先在QML外把这个实例New出来,然后再传进去,ownership也会变成QML的

              Chuck

              1 Reply Last reply
              0
              • H Offline
                H Offline
                harlentan
                wrote on last edited by
                #7

                [quote author="Chuck Gao" date="1314077832"]有一种办法是,你先在QML外把这个实例New出来,然后再传进去,ownership也会变成QML的[/quote]

                I delay binding. Then it seems work perfectly now.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  [quote author="Chuck Gao" date="1314077832"]有一种办法是,你先在QML外把这个实例New出来,然后再传进去,ownership也会变成QML的[/quote]

                  Please only use English in the general forums. Thanks!

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  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