当前位置:网站首页>QT error: no matching member function for call to ‘connect‘
QT error: no matching member function for call to ‘connect‘
2022-04-23 18:22:00 【Things will turn when they reach the extreme 1024】
error: no matching member function for call to ‘connect’
Include connect This error can also occur in functions other than , An error encountered at present , example :
// Error function
connect(ui->spinBox_HEX,&QSpinBox::valueChanged,[=](){
});
//QSpinBox::valueChanged Function declaration
Q_SIGNALS:
void valueChanged(int);
void valueChanged(const QString &);
There is no problem with such a signal connection format , however QSpinBox::valueChanged Function has overload , The compiler doesn't know which overload to use , It's a mistake . We use void valueChanged(const QString &); Format , So in connect Casts are used in
// After cast
connect(ui->spinBox_HEX,static_cast<void (QSpinBox::*)(const QString &)>(&QSpinBox::valueChanged),[=](){
});//static_cast<void (QSpinBox::*)(const QString &)>(&QSpinBox::valueChanged)
Specific writing method
connect( Control name ,static_cast< return type ( class :: *)( Parameters )>(& class :: Function name ),={
});
Another example
void currentIndexChanged(int index);
void currentIndexChanged(const QString &);
This function has two parameters
Writing method of ordinary function :
connect(ui->comboBox,&QComboBox::currentIndexChanged,[=]{
//RqDebug()<<ui->comboBox->currentText();
});
Correct usage to
void currentIndexChanged(int index); For example
First Return value void Parameters int index class QComboBox
In the original writing
&QComboBox::currentIndexChanged
remain unchanged , Add... To the front
static_cast< return type ( class :: *)( Parameters )>(&QComboBox::currentIndexChanged // Format
static_cast<void ( class :: *)( Parameters )>(&QComboBox::currentIndexChanged // Add return value
static_cast<void (QComboBox:: *)( Parameters )>(&QComboBox::currentIndexChanged // Additive
static_cast<void (QComboBox:: *)(int index)>(&QComboBox::currentIndexChanged // The last plus parameter
Finally, the actual code
connect(ui->comboBox,static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged),[=]{
qDebug()<<ui->comboBox->currentText();
});
Corresponding
void currentIndexChanged(const QString &);
connect(ui->comboBox,static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),[=]{
qDebug()<<ui->comboBox->currentText();
});
版权声明
本文为[Things will turn when they reach the extreme 1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610057331.html
边栏推荐
- QT reading and writing XML files (including source code + comments)
- Using transmittablethreadlocal to realize parameter cross thread transmission
- Climbing watermelon video URL
- Pyppeter crawler
- MySQL auto start settings start with systemctl start mysqld
- Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
- GDAL + ogr learning
- 【ACM】376. 摆动序列
- Realization of consumer gray scale
- Crawling mobile game website game details and comments (MQ + multithreading)
猜你喜欢
JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
Robocode tutorial 3 - Robo machine analysis
Gobang game based on pyGame Library
Map basemap Library
JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞
JD-FreeFuck 京东薅羊毛控制面板 后台命令执行漏洞
QT reading and writing XML files (including source code + comments)
Differences between SSD hard disk SATA interface and m.2 interface (detailed summary)
From introduction to mastery of MATLAB (2)
Robocode Tutorial 4 - robocode's game physics
随机推荐
Cutting permission of logrotate file
Daily network security certification test questions (April 14, 2022)
xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
In shell programming, the shell file with relative path is referenced
From source code to executable file
硬核解析Promise對象(這七個必會的常用API和七個關鍵問題你都了解嗎?)
Batch export ArcGIS attribute table
Serial port debugging tools cutecom and minicom
Creation and use of QT dynamic link library
Rust: a simple example of TCP server and client
The connection of imx6 network port is unstable after power on
【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
STM32 learning record 0008 - GPIO things 1
解决允许在postman中写入注释请求接口方法
Using transmittablethreadlocal to realize parameter cross thread transmission
C medium? This form of
Pointers in rust: box, RC, cell, refcell
Daily CISSP certification common mistakes (April 15, 2022)
Error reported when running tensorboard: valueerror: duplicate plugins for name projector, solution
Solving the problem of displaying too many unique values in ArcGIS partition statistics failed