[Interest] QML Action source

deDietrich Gabriel Gabriel.deDietrich at digia.com
Fri Sep 13 11:38:24 CEST 2013


Hi Daiwei,

On Sep 11, 2013, at 1:45 AM, Daiwei Li <daiweili at gmail.com> wrote:

> I'm investigating adding analytics to my QML application and would like to differentiate between reasons why an action is triggered, e.g. from a MenuItem vs keyboard shortcut vs Button press. Looking at qquickaction.cpp, this information does not seem to be made available.
> 
> What would be the best bet for getting access to this info? I'm thinking of adding an eventSource parameter to the triggered signal that would contain the objectName of the object or "shortcut+" + shortcut if it was triggered by a shortcut, but would be happy to hear other suggestions.

You could have QQuickAction::trigger() and QQuickAction::triggered() pass the (QObject) sender as an optional parameter. Then, make sure that QQuickMenuItem, BasicButton, etc. use this. (Remember that you should not emit triggered() yourself, but call trigger() instead).This is a very common pattern in other frameworks (Cocoa comes to mind), and could make sense as an API for QQuickAction. Passing some string only solves your particular problem, so that would not be acceptable as a general purpose API.

Best regards,

Dr. Gabriel de Dietrich
Senior Software Developer
qt.digia.com




More information about the Interest mailing list