QObject connection function

前端 未结 3 1873
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 04:42

I checked other similar questions and tried their solutions but they don\'t work for me.

I\'m basically trying to make a http client that only makes post requests. I

3条回答
  •  死守一世寂寞
    2020-12-06 05:09

    I share another possible problem here as this post is the top most in google search.

    In addition to add Q_OBJECT, you must also add public slots: or public Q_SLOTS: for your customized event. Otherwise, you'll still encounter the QObject::connect: No such slot error.

    I give a brief summary here according to Zeta's post and the other post

    To solve “No such slot” error, you must check..

    1. Check if your class inherits QObject or any derived class from QObject
    2. Append Q_OBJECT macro inside the class definition
    3. Append slots or Q_SLOTS after your private/protected/public keyword for your event
    4. If you do check 1-3, then clean, run qmake, and rebuild again to make sure all your things in 1-3 are generated by moc.

    Finally, a example here:

    class MyClass: public QObject { //check 1
         Q_OBJECT //check 2
    
       public slots: //check 3
         void onEvent(int);
    };
    

    Hope this saves others' life

提交回复
热议问题