[Kommander-devel] Re: Accessing a QAction in a Kommander Plugin
Eric Laffoon
eric at kdewebdev.org
Thu Feb 21 18:09:50 EST 2008
On Thursday 21 February 2008 12:44:25 pm Andras Mantia wrote:
> > Hi Eric,
> >
> > On Thursday 21 February 2008, Eric Laffoon wrote:
> >> The problem is I have to take in a QString with the name of that action
> >> and
> >> then call it. For openers, I'm not sure but I think the Actions are
> >> named
> >> with QCString. I could be wrong. Regardless I'm having a bear of a time
> >> figuring out the basic syntax and I don't have time to study this in
> >> depth.
> >> I have the Action name as declared in the editor, so it's in the ui/kmdr
> >> file. Can someone give me the syntax for a simple working function
> >> prototype here and the required include files?
> >
> > If the problem is finding the QAction pointer, you can use the child()
> > method
> > the main window inherits from QObject.
> >
> > This returns a QObject* and if you just have to change a property
> > like "enabled" you can do it right there through the setProperty()
> > method.
> >
> > Otherwise you have to cast to QAction*
>
> I am supposed to be on vacation. :) I don't have time to read all the
> mails, but what Eric would like is to execute a QAction or make it
> enabled/disabled via DCOP (yes, this is KDE3 code), just like you can do
> with the KAction's in virtually any KDE application.
>
>
> Andras
>
Hey Turkey,
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();
}
It produces the following error (code above starts at line 126)
../../src/qtactionproxy.cpp: In member function 'bool
QtActionProxy::actionIsOn(const QString&)':
../../src/qtactionproxy.cpp:128: error: expected primary-expression
before 'const'
../../src/qtactionproxy.cpp: At global scope:
../../src/qtactionproxy.cpp:126: warning: unused parameter 'action'
So... Should I be using QVariant as I have char and QString? Should I just use
a dynamic cast? Am I making stupid mistakes with pointers and references? You
know the funny thing is all this is done in kdebindings but I can't find good
example code there either. Actually KJS Embed should handle this live, but
for some reason the install I did to see if it could iterate QObjects to help
explore this has errors.
--
Eric Laffoon
Project Lead - kdewebdev module
More information about the Kommander-devel
mailing list