Qt moc with implementations inside of header files?

前端 未结 4 2008
鱼传尺愫
鱼传尺愫 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:48

    I think you can normally declare and implement the class in the header file without using anything special, eg:

    #include 
    
    class MyClass : public QObject
    {
      Q_OBJECT
    
      public:
         MyClass(QObject * parent)
         {
            // Constructor Content
         }
    
         methodExample()
         {
              // Method content
         }
    };
    

    After this you add the header file to the pri file and execute qmake again and that's it. You have a class that inherits from qobject and is implemented and declared int he .h file.

提交回复
热议问题