[Development] Possible bug in signals and slots handling in QML.

Craig.Scott at csiro.au Craig.Scott at csiro.au
Tue Jan 3 23:34:21 CET 2012


Starting a signal name with an underscore could be viewed as a violation of the C++ standard, depending on how you interpret it. Item 17.4.3.1.2 in the standard reserves names beginning with an underscore as for use only by the implementation (ie the compiler):

"17.4.3.1.2 Global names
Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore (__) or begins with an underscore followed by an upper-
case letter (2.11) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace."

This item could be interpreted as only applying to names in the global scope, but I've also seen it interpreted as applying to other names too (rightly or wrongly). Since there shouldn't be anything requiring a name to start with an underscore other than personal preference or some form of coding standard, I would recommend avoiding names that start with an underscore in your own code. There's just no reason to play in a grey area of the language.

That's all somewhat of a side issue from the ones you've raised, but it may go some way to explaining why those issues might simply be treated as "just don't do it" rather than being addressed. ;)


On 03/01/2012, at 9:25 PM, Tomasz Siekierda wrote:

> Hi,
> 
> in a recent conversation on QtDN, we have identified a possible bug in
> QML (Qt Quick 1, that is. It's possible that the both issues affect
> QtQuick2 too). We have also identified a confusing situation that can
> be easily clarified in QDoc. First, a link to the discussion, then a
> short recap on what is going on. Link:
> http://developer.qt.nokia.com/forums/viewthread/12980/#69773
> 
> 1. Capitalisation of private properties "on" slots.
> Let's consider an example:
>    property int __test: 0
>    on__test: {} // does not work!
>    on__Test: {} // does work
> 
> I think, and it seems others back me here, that this is not exactly
> intuitive. Usually, the first character gets capitalised, but in this
> case, it's the third one. It can stay this way, of course, as it's not
> a biggie, but it would be nice to update the documentation to prevent
> problems in the future. Do you agree?
> 
> 2. Signals and slots.
> Using underscores in signals does work, but no default handler is
> being generated. I'll use Lukas Geyer's example from the thread:
> Item {
>    signal publicSignal
>    signal __privateSignal
> 
>    onPublicSignal: { 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
> }
> 
> Is that an intended behaviour? Or maybe the handlers are being
> created, but using a different naming scheme?
> 
> Best regards, and a happy new year,
> sierdzio
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

--
Dr Craig Scott
Computational Software Engineering Team Leader, CSIRO (CMIS)
Melbourne, Australia






More information about the Development mailing list