From kde-devel Thu May 24 21:20:35 2007 From: Andreas Pakulat Date: Thu, 24 May 2007 21:20:35 +0000 To: kde-devel Subject: Re: actionCollection()->addAction( "edit_new" ) not acting as expected Message-Id: <20070524212035.GJ13297 () morpheus ! apaku ! dnsalias ! org> X-MARC-Message: https://marc.info/?l=kde-devel&m=118004168904345 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( 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 <<