Qt moc with implementations inside of header files?

前端 未结 4 2013
鱼传尺愫
鱼传尺愫 2020-11-30 11:27

Is it possible to tell the Qt MOC that I would like to declare the class and implement it in a single file rather than splitting them up into an .h and .cpp file?

4条回答
  •  死守一世寂寞
    2020-11-30 11:58

    If you want to declare and implement a QObject subclass in you cpp file, you have to manually include the moc file.

    For example: (file main.cpp)

    struct SubObject : QObject
    {
        Q_OBJECT
    };
    
    //...
    
    #include "main.moc"
    

    You have to rerun moc (make qmake) after adding the #include statement.

提交回复
热议问题