gpt4 book ai didi

c++ - Qt 没有匹配函数供调用

转载 作者:行者123 更新时间:2023-11-30 02:10:55 25 4
gpt4 key购买 nike

我试图将按钮点击连接到一个函数,并传递一个 int 值,但不断收到错误消息:没有匹配的函数调用 Main::connect...我猜我不是初始化正确吗?

主窗口.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);

}

主窗口.h

ublic:
MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void parseXML();
void addMenu(int count);

signals:
void clicked();

最佳答案

您的代码中存在语法错误。计算你的括号:

connect(button, SIGNAL(clicked())), signalMapper, SIGNAL(map());
// ^ ^ ^^^^
// 1 2 3321 <-- All your parenthesis are closed at this point
// meaning you are calling connect() with only 2 parameters

关于c++ - Qt 没有匹配函数供调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4167397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com