proposed KAction/KActionCollection API changes

Olivier Goffart ogoffart at
Tue Jan 2 22:16:47 GMT 2007

Le mardi 2 janvier 2007 22:30, Simon Hausmann a écrit :
> Hi,
> The result for application code is that it becomes a lot more verbose:
> KAction *a = new KAction(i18n("&Reload"), "reload", CTRL + Key_F5, this,
> SLOT(reload()), actionCollection(), "view_reload");
> becomes
> KAction *a = new KAction(KIcon("reload"), i18n("&Reload"), this);
> a->setShortcut(Qt::ControlModifier + Qt::Key_F5);
> connect(a, SIGNAL(triggered()), this, SLOT(reload());
> actionCollection()->addAction("view_reload", a);
> Or alternatively:
> KAction *a = actionCollection()->addAction("view_reload");
> a->setShortcut(Qt::ControlModifier + Qt::Key_F5);
> connect(a, SIGNAL(triggered()), this, SLOT(reload());
> What do people think about this?

Yes, i think theses changes are needed soon or later.
You have done great work, fine.

Anyway, in general, we create a lot of KAction in the same time.
So i think it was a benefit to create one action in one line. I find it aesthetic.

Also, addAction sometimes create a new object, and sometimes doesn't. maybe
the addAction() which create a new KAction should be newAction()

actionCollection()->newAction("view_reload",  i18n("&Reload"), KIcon("reload"), CTRL+Key_F5,   this, SLOT(reload()) );
actionCollection()->newAction("history_back", i18n("&Back"),   KIcon("back"),   ALT+Key_Left,  this, SLOT(back()) );
actionCollection()->newAction("history_next", i18n("&Next"),   KIcon("next"),   ALT+Key_Right, this, SLOT(next()) );

This look beautiful, is less verbose, but isn't more hard to read (i think)

also, the text+icon could be a KGuiItem ?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the kde-core-devel mailing list