customplaceholder没有匹配函数调用QT标签

Customplaceholder has no matching function to call QT label

我的 QT 项目有问题。我想创建一个可触摸的 Qlabel,所以我在 gui 设计器中创建了一个占位符并将其引用到我的 "watchlistlabel",它从 QLabel 扩展。当我现在启动我的应用程序时,我收到错误消息“没有匹配函数来调用 WatchListLabel::WatchListLabel(QGroupBox*&)” name1 = new WatchListLabel(groupBox_3);

我的标签在一个分组框中,这会影响我的代码吗? 为什么找不到匹配的函数? ^

 #include<QLabel>

  class WatchListLabel: public QLabel
{
   Q_OBJECT
  private: 
     void mousePressEvent(QMouseEvent * event) override;
 public:
    WatchListLabel();
 };

watchlistlabel.cpp

  #include "watchlistlabel.h"

 void WatchListLabel::mousePressEvent(QMouseEvent *event)
 {



    }

  WatchListLabel::WatchListLabel()
 {

 }

QTdesigner

您缺少一个采用父窗口小部件的构造函数。对此的一般建议是使用 Qt Creator new class 向导创建新的 QObject subclasses,它将使一切正常。但是要解决此 class 的问题,请尝试用此构造函数替换您的默认构造函数:

.h 中的声明:

explicit WatchListLabel(QWidget *parent = nullptr);

.cpp 中的定义:

WatchListLabel::WatchListLabel(QWidget *parent)
    : QLabel(parent) 
    //, any other member variable initializations
{
    // any constructor code if needed
}