[solved] c++ equvalent of "property alias"
-
Hi,
What would be the c++ equivalent of "property alias" from qml?
I have a class extending QQuickText in which I create 2 child QQuickText objects like this:
@
class XLabel : public QQuickText
{
Q_OBJECTpublic:
QQuickText *probe, *label1, *label2;
void createLabels();
....
}void XLabel::createLabels(){
label1 = new QQuickText(this);
label2 = new QQuickText(this);
// here the equivalent of property alias ...
}
@I need to expose these 2 child labels in the main object so they are accessible from QML.
In QML I would do like this:@
Text{property alias t1:label1; // <-- how can I do this in c++ ? property alias t2:label2; Text{ id:label1; } Text{ id:label2; }
}
@So how can I do this from c++ ?
-
I think there is no such mechanism in C++. You need to declare those properties by hand.
-
[quote author="Katlin" date="1416997981"]You mean like we do with all the properties, using Q_PROPERTY ? Would that work on a QQuickText* variable ?[/quote]
Yes and yes. QQuickText is still a Q_OBJECT, so all the magic from MOC is available here.
-
Yes, it should work. Remember the QML engine relies on NOTIFY signal to manage bindings, so you need to have that declared and used in your property functions.
-
Ok, it solved my problem, thx! Now on click I do have access to the sub-labels.
But now there is another problem; may I direct your attention to it: https://qt-project.org/forums/viewthread/50047/ ? -
Thanks for the link, but this time I do not know the answer.