Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions

does parentClass's Q_OBJECT work for nestedClass?



  • does parentClass's Q_OBJECT work for nestedClass?
    i found this is illegal:

    class P : publica QWidget
    {
        Q_OBJECT
    protected:
        class N : public QWidget
        {
            Q_OBJECT
        }
    }
    

    so can i write like this?

    class P : publica QWidget
    {
        Q_OBJECT
    protected:
        class N : public QWidget
        {
            //Q_OBJECT
        }
    }
    


  • @opengpu said in does parentClass's Q_OBJECT work for nestedClass?:

    so can i write like this?

    Yes (as long as you don't declare signal/slots/properties/invokables in the inner class). Whether you should is another topic.

    i found this is illegal:

    It's not illegal per-se it's just that moc is not smart enough to handle it. It is valid if you skip moc using, for example, Verdigris


Log in to reply