QActions in QML

Sebastian Kügler sebas at kde.org
Tue Oct 30 15:09:20 UTC 2012


On Tuesday, October 30, 2012 16:01:37 Kevin Krammer wrote:
> On Tuesday, 2012-10-30, Sebastian Kügler wrote:
> > On Monday, October 29, 2012 13:46:18 Marco Martin wrote:
> > > On Monday 29 October 2012, Daker Fernandes Pinheiro wrote:
> > > > > > Daker Fernandes Pinheiro
> > > > > > http://codecereal.blogspot.com
> > > > > 
> > > > > isn't QAction already registered as "action" primitive type?
> > > > 
> > > > At least not on QtQuick 1.1
> > > 
> > > not sure if is really qaction or some wrapper class, but
> > > http://qt-project.org/doc/qt-4.8/qml-action.html
> > 
> > I don't know either. Using QAction as QtObject in QML works. On the other
> > hand, QAction doesn't have trigger() as Q_INVOKABLE, yet it is one for the
> > runtime (one can just call trigger() on a QAction passed into the runtime.
> 
> Sorry for jumping into this thread, but trigger() is a slot (public even),
> so it should be invokable even without Q_INVOKABLE.

Ah, ok. Thought it really needed the Q_INVOKABLE macro.

> In any case, I am curious what the use case of triggering a UI action is?
> I mean any imperative portion of the QML could just invoke the script
> function the action's onTriggered is calling, no?

In Plasma Desktop, we have pluggable actions, which exist as QActions for 
example in Corona (think of "Lock widgets", "Add Widgets", "Activities", 
etc.).

In order to do a fully functional containment (and toolbox) in QML, we need 
access to these actions, and we need to be able to trigger them. So, basically 
a QML button receives an action object from the C++ side and is able to call 
trigger on it when the button is clicked. The trigger() function in this case 
is not scripted, but lives "somewhere else".
-- 
sebas

http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9


More information about the Plasma-devel mailing list