No matching function for QObject::connect

后端 未结 4 1176
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 11:50

I\'m writing a program that send an UDP frame every 10 mS. Here\'s how my program is supposed to work :

I\'ve got a client class :

//Con         


        
4条回答
  •  暖寄归人
    2021-01-11 12:15

    There can be several reasons for the issue in general:

    • You do not inherit QObject.

    • You do not have the Q_OBJECT macro in your class.

    • You do not define the method as slot in your header file where the class is declared.

    Your issue is the first which can be seen here:

    class clientSupervision
    

    You should change your code to:

    class clientSupervision : public QObject
    //                      ^^^^^^^^^^^^^^^^
    

    Of course, the constructor implementation and signature would need to change, too, as follows:

    explicit clientSupervision(QObject *parent = Q_NULL_PTR) : QObject(parent) { ... }
    

    In addition, you seem to leak your QTimer instance as it does not get the parent as a parameter to the constructor.

    Furthermore, the QObject:: scope is needless in your code as your class ought to inherit QObject directly or indirectly either way.

    Even more, I would highly encourage you to utilize the new signal-slot syntax.

提交回复
热议问题