Using a macro to create QObject derived classes

前端 未结 3 1131
执笔经年
执笔经年 2021-01-06 01:36

I\'m trying to simplify (i.e. get rid of loads of boilerplate code) the creation of QObject wrapper classes that forward property access of other QObject<

3条回答
  •  执笔经年
    2021-01-06 02:37

    moc doesn't like macros very well. It expands them to some degree, but it fails when they get complicated¹.

    You can try to replace signals: with public:² (i.e. manually expanding the signals macro), andtell moc that you want the function to be a signal by putting Q_SIGNAL in front of the function declaration.

    Replace

    signals:\
        void Notifier( Type value );\
    

    with

    public:\
        Q_SIGNAL void Notifier( Type value );\
    

    ¹: for some definition of complicated... I don't know when it fails, but I ran into some different problems in the past. From my experience my guess is that moc has problems when a macro body contains another macro, like signals in your example. But this is just a guess - maybe the kind of macros moc fails at is something else.

    ²: Before Qt 5, that used to be protected.

提交回复
热议问题