QT没有这样的插槽
QT no such slot
我有这样一段代码:
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
component.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)
它发生后,我移动槽和信号的定义从组件到它的派生类Przystanki。我已经删除了整个构建目录,运行clean,运行qmake和构建一次,它没有帮助。有人能告诉我我哪里做错了吗?
你的类Przystanki缺少Q_OBJECT宏。添加它,将przystanki.h添加到.pro文件中的HEADERS(如果还没有)并重新运行qmake.
相关文章:
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 如何在qt中将信号和插槽与另一个对象连接 --解决了
- QT 插槽未在主线程上调用
- 通过插槽和信号在不同线程中的两个qt对象之间进行通信
- 控制带有信号/插槽的Qt QML滑动视图
- Qt 信号/插槽问题
- Qt信号和插槽如果从QRunnable或其他线程调用,则不起作用
- Qt插槽调用了两次
- C++Qt信号和插槽
- Qt moveToThread,带有参数的信号/插槽
- 当再次触发信号时,从Qt插槽执行的功能被第二次调用时会发生什么?
- 在Qt中执行完所有插槽后,如何释放对象
- 使用std::bind将Qt信号连接到插槽
- 在Qt中使用C++Lambda函数作为插槽是否有助于保持库的二进制兼容性?
- Qimage没有通过信号插槽QT
- 将一个信号连接到多个插槽 Qt
- 为什么我不能从基类插槽Qt调用虚函数
- 动态创建自定义小部件的新实例并连接信号和插槽(Qt)
- 将QML信号连接到c++ 11 lambda插槽(Qt 5)
- 发射信号和插槽 (Qt) 的信息和控制