Trying to understand moc

Simon Hausmann hausmann at kde.org
Thu Mar 29 19:26:53 BST 2007


On Thursday 29 March 2007 19:57:22 Andreas Pakulat wrote:
> Hi,
>
> IIRC there are two "points of contact" at TT reading this list (don't
> remember the names though), I'd like to understand some weirdness wrt.
> to moc and interfaces in Qt4.
>
> Qt's Designer has some nice API to define extension interface which
> KDevelop and the KDevPlatform code is using to have plugins that can
> break BC anytime, without breaking the application. There's
> unfortunately a minor problem with this:
>
> The macro's that are defined to declare an extension interface do not
> work when having the interface inside a Namespace. The issue is easily
> fixable by providing a new macro that takes the namespace as a separate
> parameter and KDevelop defines such a macro.
>
> This KDEV_DECLARE_EXTENSION_INTERFACE macro looks very similar to
> Q_DECLARE_EXTENSION_INTERFACE, but for some reason it can't embed the
> Q_DECLARE_INTERFACE macro in it (like the Q_DECLARE_EXTENSION_INTERFACE
> maro does). The problem here is that moc then doesn't know about the
> declared interface and bails out when moccing the plugin's header that
> has
>
> Q_INTERFACES( IFace )
>
> I tried to read the moc parsing code, but didn't succeed as to why
> Q_DECLARE_EXTENSION_INTERFACE works, but out own macro doesn't. But the
> parsing code is rather complex and seems to be generated. I didn't see
> any code that recognizes Q_DECLARE_EXTENSION_INTERFACE and treats it
> specially, so there must be something else...
>
> So basically I'm looking for a way to not have to use vthe
> Q_DECLARE_INTERFACE macro  when defining an interface (i.e. 2 macros,
> the KDEV one because of the NS and the Q one for moc). The attached code
> demonstrates the problem, just run it through moc and you see it
> complains for the first macro but doesn't for the other 2.
>
> I'm happy to report this as a bug to TT if somebody says it looks like
> one, it certainly doesn't look like a bug to me (yet).

It's not really a bug, but I may be able to shed some light on this :)

Originally moc only knew Q_DECLARE_INTERFACE but then Roberto started using 
Q_DECLARE_EXTENSION_INTERFACE in Designer. Sitting next to the source we 
added a hack to moc's tokenizer to map "Q_DECLARE_EXTENSION_INTERFACE" to the 
same token type as "Q_DECLARE_INTERFACE", namely Q_DECLARE_INTERAFCE_TOKEN. 
That is why you don't see anything about the extension macro in moc.cpp, it's 
all handled in ppkeywords.cpp.

So unfortunately there's no way to make moc know about 
K_DECLARE_EXTENSION_INTERFACE from the outside until we get around 
implementing full macro substitution.

But I believe the solution to your original problem is much simpler:

namespace Foo
{
    struct MyInterface
    {
        ...
    };
}

Q_DECLARE_INTERFACE(Foo::MyInterface, "your.interface.name")

(this is also hidden in the documentation at 
http://doc.trolltech.com/4.2/qtplugin.html#Q_DECLARE_INTERFACE )

Does this help? :)

Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070329/3811968b/attachment.sig>


More information about the kde-core-devel mailing list