QML private properties
-
[quote author="sierdzio" date="1325582995"]Please, verify first.
I've tried again now, and it seems I was partially wrong. Underscores in signals do not work at all! MOC throws an error at runtime. But Qt Creator allows to write the syntax I provided above (with underscores but no capitalisation).[/quote]Even though Qt Creator allows it, it looks like there are no signal handlers generated for signals not starting with a letter.
@
Item {
signal publicSignal
signal _privateSignalonPublicSignal: { console.debug('onPublicSignal') } on_PrivateSignal: { console.debug('on_PrivateSignal') } on_privateSignal: { console.debug('on_privateSignal') }
}
Cannot assign to non-existent property "on_PrivateSignal"
Cannot assign to non-existent property "on_privateSignal"
@Which raises another question - intended behaviour or bug (as Qt and moc do support signals starting with underscores) ;-)
-
Well, as it turns out signals with underscores do work, but there are no handlers generated or there is a naming scheme used I haven't figured out yet.
@
Item {
signal publicSignal
signal __privateSignalonPublicSignal: { console.debug('onPublicSignal') } Component.onCompleted: { publicSignal(); // does work __privateSignal(); // does work too } on__PrivateSignal: { console.debug('on_privateSignal') } // does not work, undefined property on__privateSignal: { console.debug('on_privateSignal') } // does not work, undefined property
}
@ -
Best way now is to ask on development ML. I'll do that now.
-
Done. I'll report any news that we get from there.
-
Fine. Thanks.
-
Looks like I started a debate here.
In the meantime I'm declaring private properties that way:
@property bool pTest@Thanks guys.
-
Right, we've got some answers.
The capitalisation for signals with double underscores works in Qt5, but will not be ported back to 4.x
Capitalising the first actual letter is intentional and will stay this way.
Craig also responded with some useful info on using underscores in C++ code (it's reserved by ISO standard)
Conversation can be followed here: "link":http://lists.qt-project.org/pipermail/development/2012-January/001149.html.
-
Thanks for reporting back. Quite interesting that symbol names with preceding underscores can be seen as "just don't do it", although Qt itself uses them extensively ;-)
However, if I get things right this does not effect QML, signals with preceding underscores should work and will do so with Qt5.
-
Yeah, I've raised the same point in my reply to Craig.
AFAIK, QML "talks" directly with MOC, passing signal names as strings - so C++ standard should have nothing to say here. But I may be wrong. And definitely it's a good thing to remember that such a clause happens to exist in the ISO standard.
-
Hi,
I find this thread cause there is an issue with QtCreator that push me in mistake. QtCreator find this "on__OriginXChanged" invalid and "on__originXChanged", but the first one with the upper case is the property name working when the application runs.
PS : I use Qt 5.2