No matching function for QObject::connect

后端 未结 4 1169
伪装坚强ぢ
伪装坚强ぢ 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 11:56

    If none of the answers above worked, check if you have assigned correct object to the signals and the slots. You will get this error when the signals and slots are valid and refer to one object but the object assigned to that signal and slot is different.

    0 讨论(0)
  • 2021-01-11 11:59

    Here's another one that snuck up on me: The class of the slot object had been forward declared in the header, but not defined in the implementation by including its header.

    0 讨论(0)
  • 2021-01-11 12:03

    Another possible cause of this error is trying to connect to a slot which is overloaded. For example, this well cause the same error

    QObject::connect(this,
                     &MazeWidget::MyUpdate,
                     this, 
                     &QWidget::update,
                     Qt::QueuedConnection);
    

    But not if you explicitely cast:

    QObject::connect(this,
                     &MazeWidget::MyUpdate,
                     this,
                     static_cast<void (QWidget::*)()>(&QWidget::update),
                      Qt::QueuedConnection);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题