[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: actionCollection()->addAction( "edit_new" ) not acting as expected
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2007-05-24 21:20:35
Message-ID: 20070524212035.GJ13297 () morpheus ! apaku ! dnsalias ! org
[Download RAW message or body]

On 24.05.07 22:04:22, dave selby wrote:
> I am looking at some code ...
> 
>   QAction* newAct = actionCollection()->addAction( "edit_new" );
>   newAct->setText( i18n("&New...") );
>   newAct->setIcon( KIcon("document-new") );
>   qobject_cast<KAction*>( newAct
> )->setShortcut(KStandardShortcut::shortcut(KStandardShortcut::New));
>   connect(newAct, SIGNAL(triggered(bool)), SLOT(slotEditNew()));
> 
> The key part being ...
> 
>   QAction* newAct = actionCollection()->addAction( "edit_new" );
> 
> According to Kross::ActionCollection Class Reference, this gives the
> action 'newAct' a name - in this case "edit_new".

I think you have the wrong class doc, Kross::ActionCollection doesn't
have such a method addAction taking only 1 qstring parameter. But
KActionCollection does have such a method. And KActionCollection doesn't
do anything with the name except using it in an internal lookup-table
for actions it already know about.

> There is a connect in the form ...
> 
>   connect(editMenu,SIGNAL(hovered(QAction*)),this,SLOT(statusEditCallback(QAction*)));
> 
> Followed by ...
> 
> void KTApp::statusEditCallback(QAction* action)
> {
>   cout << "XXXXXXXXX" << action->name() << endl;
> 
> And I end up with zip but a lot of X's whenever I hover over the 'new'
> option. I get the expected result when I action->text() but then I get
> '&New ...' not 'edit_new' !

name() is an inherited Qt3 support method from QObject and (IIRC) should
be the same as objectName(). That property is never automatically set,
so you have to set it yourself.

> Interestingly the KStandardAction cut, copy, paste work as expected
> and returns 'edit_cut', 'edit_copy' ... etc.

That is because those actions are setup using setObjectName("edit_cut"),
I guess (didn't look up in the source).

> Have been googleing & struggling on this - documentation on
> 'actionCollection' seems a bit light :)

No, you just look at the wrong docs. I guess you started at the wrong
point, actionCollection() is a method on KMainWindow (and its
subclasses) not a constructor. And the api for that method would've sent
you to KApplication.

Andreas

-- 
Stay away from flying saucers today.
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic