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



  • 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.

    :)



  • Yes, for your answer



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



  • 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



  • [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



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



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

    I delay binding. Then it seems work perfectly now.


  • Moderators

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

    Please only use English in the general forums. Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.