KShortcut and properties

Thiago Macieira thiago at kde.org
Tue Apr 17 16:19:00 BST 2007


Jakub Stachowski wrote:
> Hello,
>
> KAction has two properties of type KShortcut: shortcut and globalShortcut.
> The
> problem is that KShortcut is not registered with Qt metatype system so it
> cannot really be used as type of property. This causes bug in
> KXMLGUIFactory::configureAction - it reads shortcuts from .ui file (
> ActionProperties node) and tries to set them using setProperty("shortcut",
> [QString with shortcut definition]. This will fail because bug mentioned
> above and because QString won't be casted to KShortcut automatically.
> Attached is patch that fixes both KShortcut-as-property problem (did i put
> qRegisterMetaType calls in proper places?) and casting in KXMLGUIFactory.

Patch looks good.

Just the following:
 #include <QtCore/QList>
 #include <QtGui/QKeySequence>
+#include <QMetaType>

it should be QtCore/QMetaType.

While you're at it, here are some suggested improvements for KShortcut:
* add operator QVariant() const { return qVariantFromValue(*this); }, just
like QKeySequence has it.
  Unlike KUrl, KShortcut's base class won't cause us problems

* make qHash(const KShortcut &) non-inline. I don't think it's a good idea
to have qHash on a Qt type (QKeySequence) in one of our public header
files. Actually, the whole qHash function looks dangerous to me the way it
is written.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358






More information about the kde-core-devel mailing list