[Kommander-devel] Re: Accessing a QAction in a Kommander Plugin

Kevin Krammer kevin.krammer at gmx.at
Sat Feb 23 11:18:00 EST 2008


Hi Eric,

On Friday 22 February 2008, Eric Laffoon wrote:

> I didn't expect to hear from you. Actually I'm not using DCOP, but a
> Kommander plugin to access QActions by proxy. I have the concept and
> everything looks good except how to get it to talk to the QAction. Kevin's
> idea seems good, I just can't seem to get the syntax with my weak C++
> abilities.
>
> This won't compile...
> bool QtActionProxy::actionIsOn(const QString& action)
> {
>   return QObject::child(const char * action)->property("isOn").toInt();
> }

You will need a pointer to the main window.

e.g.

bool QtActionProxy::actionIsOn(const QString& action)
{
  QObject* childObject = mainWindow->child(action.utf8(), "QAction");
  if (childObject == 0) return false;

  return childObject->property("on").toBool();
}

I had a quick look at the 3.5 branch source of Kommander and there seems to be 
a KmdrMainWindow class (in kommander/widget) so you could probably place your 
code in there if this is the class the executor creates when it encounters a 
QMainWindow in the XML file.

In this case you the code is almost the same, just without the "mainWindow->" 
part.

> So... Should I be using QVariant as I have char and QString? Should I just
> use a dynamic cast?

A dynamic cast solution would look like this:

bool QtActionProxy::actionIsOn(const QString& action)
{
  QAction* childAction = dynamic_cast<QAction*>(mainWindow->child(action.utf8
(), "QAction"));
  if (childAction == 0) return false;

  return childAction->isOn();
}

Cheers,
Kevin
-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mail01.fortunecookiestudios.com/pipermail/kommander-devel/attachments/20080223/db900815/attachment.pgp


More information about the Kommander-devel mailing list