QML property assign is after the C++ constructor??
-
wrote on 23 Aug 2011, 02:14 last edited by
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.
:)
-
wrote on 23 Aug 2011, 04:29 last edited by
Yes, for your answer
-
wrote on 23 Aug 2011, 04:30 last edited by
And i know who are you right now. :-)
-
wrote on 23 Aug 2011, 05:14 last edited by
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 -
wrote on 23 Aug 2011, 05:27 last edited by
[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 -
wrote on 23 Aug 2011, 05:37 last edited by
有一种办法是,你先在QML外把这个实例New出来,然后再传进去,ownership也会变成QML的
-
wrote on 23 Aug 2011, 07:12 last edited by
[quote author="Chuck Gao" date="1314077832"]有一种办法是,你先在QML外把这个实例New出来,然后再传进去,ownership也会变成QML的[/quote]
I delay binding. Then it seems work perfectly now.
-
wrote on 23 Aug 2011, 16:04 last edited by
[quote author="Chuck Gao" date="1314077832"]有一种办法是,你先在QML外把这个实例New出来,然后再传进去,ownership也会变成QML的[/quote]
Please only use English in the general forums. Thanks!
8/8