Qt 没有匹配的调用函数
我正在尝试将按钮单击连接到函数,并传递 int 值,但不断收到错误:没有调用 Main::connect 的匹配函数...我猜我没有初始化正确的东西?
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
setupUI();
}
MainWindow::~MainWindow() {
}
void MainWindow::setupUI() {
QFrame* frame = new QFrame(this);
_layout = new QVBoxLayout;
frame->setLayout(_layout);
parseXML();
QScrollArea* scrollArea = new QScrollArea;
scrollArea->setWidget(frame);
scrollArea->setWidgetResizable(true);
setCentralWidget(scrollArea);
}
void MainWindow::parseXML() {
this->parseItem(xml, count)
}
QMap<QString, QString> MainWindow::parseItem(QXmlStreamReader& xml, int count) {
QString valueName = "buttonid";
QSignalMapper *signalMapper = new QSignalMapper(this);
QPushButton* button = new QPushButton(valueName);
_layout->addWidget(button);
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(addMenu(int)));
signalMapper->setMapping(button, valueName);
connect(button, SIGNAL(clicked())), signalMapper, SIGNAL(map());
return something;
}
void MainWindow::addMenu(int count) {
_layoutToAdd = new QVBoxLayout;
QPushButton* button = new QPushButton("New Button");
_layoutToAdd->addWidget(button);
_layout->insertLayout(count, _layoutToAdd, 0);
}
mainwindow.h
ublic:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void parseXML();
void addMenu(int count);
signals:
void clicked();
I'm trying to connect a button click to a function, and pass an int value, but keep getting an error: no matching function for call to Main::connect... I'm guessing that I'm not initializing something correct?
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
setupUI();
}
MainWindow::~MainWindow() {
}
void MainWindow::setupUI() {
QFrame* frame = new QFrame(this);
_layout = new QVBoxLayout;
frame->setLayout(_layout);
parseXML();
QScrollArea* scrollArea = new QScrollArea;
scrollArea->setWidget(frame);
scrollArea->setWidgetResizable(true);
setCentralWidget(scrollArea);
}
void MainWindow::parseXML() {
this->parseItem(xml, count)
}
QMap<QString, QString> MainWindow::parseItem(QXmlStreamReader& xml, int count) {
QString valueName = "buttonid";
QSignalMapper *signalMapper = new QSignalMapper(this);
QPushButton* button = new QPushButton(valueName);
_layout->addWidget(button);
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(addMenu(int)));
signalMapper->setMapping(button, valueName);
connect(button, SIGNAL(clicked())), signalMapper, SIGNAL(map());
return something;
}
void MainWindow::addMenu(int count) {
_layoutToAdd = new QVBoxLayout;
QPushButton* button = new QPushButton("New Button");
_layoutToAdd->addWidget(button);
_layout->insertLayout(count, _layoutToAdd, 0);
}
mainwindow.h
ublic:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void parseXML();
void addMenu(int count);
signals:
void clicked();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码中存在语法错误。数一下你的括号:
There's a syntax error in your code. Count your parenthesis :
您必须在类的描述中使用白色 Q_OBJECT (用于使用信号和槽)
You must white Q_OBJECT (for using signals and slots ) in descriction of your class