c++ - QT没有这样的插槽

标签 c++ qt

<分区>

我有这样一段代码:

przystanki.h

#ifndef PRZYSTANKI_H
#define PRZYSTANKI_H
#include "component.h"
class Przystanki : public Component
{
public:
    Przystanki(QWidget *parent = 0);

signals:
    void deletePosition(QString);
public slots:
    void deleteListItem();
    void addListItem(QString label);
    void createListItem(QString label, DodajPrzystanek* elem);

};

#endif // PRZYSTANKI_H

组件.h

#ifndef COMPONENT_H
#define COMPONENT_H
#include <QListWidget>
#include <QGroupBox>
#include "dodajprzystanek.h"
class Component : public QGroupBox
{
    Q_OBJECT
public:
    explicit Component(QString name, QWidget *parent = 0);
    QListWidget* list;

};

#endif // COMPONENT_H

使用它的片段:

MyWindow::MyWindow(QWidget *parent) :
QMainWindow(parent)
{
webView = new MyWebView(this);
mainlayout = new QGridLayout();
mainlayout->addWidget(webView, 0,0);
Przystanki *stop = new Przystanki(this);
mainlayout->addWidget(stop, 0, 1);
QHBoxLayout* bottom = new QHBoxLayout();
//bottom->addWidget(new QLabel("Linie"));
bottom->addWidget(new Component("Autobusy"));
bottom->addWidget(new Component("Linie"));
QHBoxLayout* hrightCorner = new QHBoxLayout();
QVBoxLayout* rightCorner = new QVBoxLayout();
rightCorner->addStretch(1);
rightCorner->addWidget(new QPushButton("Start", this));
//QLabel* label = new QLabel("Labelka");

//rightCorner->addWidget(label);
rightCorner->addStretch(1);
hrightCorner->addLayout(rightCorner);
mainlayout->addLayout(bottom, 1, 0);
mainlayout->addLayout(hrightCorner, 1, 1);
hrightCorner->setAlignment(Qt::AlignCenter);
this->setCentralWidget(new QWidget);
this->centralWidget()->setLayout(mainlayout);
connect(webView, SIGNAL(getMapPosition(QString)), stop, SLOT(addListItem(QString)));
connect(stop, SIGNAL(deletePosition(QString)), webView, SLOT(deleteMarker(QString)));


}

我得到的是:

loaded the Generic plugin 
Object::connect: No such slot Component::addListItem(QString)
Object::connect: No such signal Component::deletePosition(QString)

这发生在我将插槽和信号的定义从 Component 移动到它的派生类 Przystanki 之后。我已经删除了整个构建目录,运行干净,运行 qmake 并再次构建一次,但没有帮助。谁能向我解释我做错了什么?

最佳答案

您的 Przystanki 类缺少 Q_OBJECT 宏。添加它,将 przystanki.h 添加到 .pro 文件中的 HEADERS(如果还没有)并重新运行 qmake。

关于c++ - QT没有这样的插槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14304113/

相关文章:

c++ - 从逆序C++访问 vector 时发生运行时错误

c++ - 如何删除作为 C++ union 的成员变量的字符串对象?

C++ 文件在第一行后停止读取

qt: pyqt: QTreeView 内部拖放几乎可以正常工作...拖动的项目消失

qt - 学习诺基亚应用从哪里开始?

qt - 复选框的组合框?

c++ - 为什么 'this' 指针在通过引用返回以进行运算符赋值时被取消引用?

c++ - 如何将指定行数作为输入?

javascript - Qt编程: How to use custom data type in QVariantMap?

c++ - QTabWidget 中缺少图标