课程网站开发过程,东莞外贸模板建站,为网站做seo需要什么,网页设计与网站建设问题
在Qt中#xff0c;重载的信号默认是无法使用这种方式调用的。 因为只能绑定到一个具体的信号#xff0c;而重载的信号名称相同#xff0c;编译器无法确定要绑定哪一个信号。
解决方案
如果非要使用绑定重载的信号#xff0c;可以使用函数指针进行转…问题
在Qt中重载的信号默认是无法使用这种方式调用的。 因为只能绑定到一个具体的信号而重载的信号名称相同编译器无法确定要绑定哪一个信号。
解决方案
如果非要使用绑定重载的信号可以使用函数指针进行转换指定参数类型和个数例如
signals:void sendMsg(int n);void sendMsg(QString str);connect(this, static_castvoid (MainWindow::*)(const int)(MainWindow::sendMsg), this, [](int n){qDebug().noquote() [ __FILE__ __LINE__ ] n : n;});connect(this, static_castvoid (MainWindow::*)(const QString)(MainWindow::sendMsg), this, [](QString str){qDebug().noquote() [ __FILE__ __LINE__ ] str : str;});示例
.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include QMainWindownamespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent nullptr);~MainWindow();signals:void sendMsg(int n);void sendMsg(QString str);private:Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
.cpp
#include mainwindow.h
#include ui_mainwindow.h#include QDebugMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui-setupUi(this);connect(this, static_castvoid (MainWindow::*)(const int)(MainWindow::sendMsg), this, [](int n){qDebug().noquote() [ __FILE__ __LINE__ ] n : n;});connect(this, static_castvoid (MainWindow::*)(const QString)(MainWindow::sendMsg), this, [](QString str){qDebug().noquote() [ __FILE__ __LINE__ ] str : str;});emit sendMsg(1);emit sendMsg(helloworld);
}MainWindow::~MainWindow()
{delete ui;
}main.cpp
#include mainwindow.h
#include QApplicationint main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}结果