本文介绍了Moc中的宏扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想使用Q_CLASSINFO宏存储一些类信息.但是,我想将其包装在自己的宏中,例如:

I'd like to store some class info using Q_CLASSINFO macro. However I would like to wrap it in my own macro, for example:

#define DB_TABLE( TABLE ) \
    Q_CLASSINFO( "db_table", #TABLE )

#define DB_FIELD( PROPERTY, COLUMN ) \
    Q_CLASSINFO( "dbcol_" #PROPERTY, #COLUMN )

class Foo : public QObject
{
    Q_OBJECT
    DB_TABLE( some_table )
    DB_FIELD( clientName, client_name )
}

不幸的是,moc不会扩展宏,因此未添加Q_CLASSINFO.

Unfortunately, moc doesn't expand macros so the Q_CLASSINFO is not added.

我试图用已经预处理过的源代码来提供moc,但是在某些包含的Qt类上却失败了.

I've tried to feed moc with already preprocessed source, but it failes on some included Qt classes.

您知道任何解决方法吗?

Do you know any workaround for this?

推荐答案

除了滚动您自己的pre-moc预处理程序外,没有.例如,MeeGo Touch就是这样做的.由于诺基亚本身正在这样做,所以我相信别无他法.

Other than rolling your own pre-moc preprocessor, no. That is what MeeGo Touch does, for example. Since Nokia themselves are doing it, I believe there is no other way.

在您的情况下,它仅涉及将您自己的声明转换为Q_CLASSINFO,因此应该不会太难.如果使用qmake,它也可以添加到构建序列中.

In your case, it would only involve translating your own declarations into Q_CLASSINFO, so it shouldn't be too hard. If you use qmake, it can be added to the build sequence, too.

这篇关于Moc中的宏扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:28