当前位置:网站首页>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
边栏推荐
- How to install jsonpath package
- Pointers in rust: box, RC, cell, refcell
- Daily CISSP certification common mistakes (April 18, 2022)
- CISSP certified daily knowledge points (April 13, 2022)
- Quantexa CDI(场景决策智能)Syneo平台介绍
- Quantexa CDI(场景决策智能)Syneo平台介绍
- Reptile efficiency improvement method
- Function recursion and solving interesting problems
- Linux installs MySQL in RPM (super simple)
- Robocode Tutorial 4 - robocode's game physics
猜你喜欢

Deep learning classic network analysis and target detection (I): r-cnn

logstash 7. There is a time problem in X. the difference between @ timestamp and local time is 8 hours

Use of regular expressions in QT

Jenkspy package installation

JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞

WiFi ap6212 driver transplantation and debugging analysis technical notes

Robocode Tutorial 4 - robocode's game physics

Installation du docker redis

Solution to Chinese garbled code after reg file is imported into the registry

【ACM】376. 摆动序列
随机推荐
Daily CISSP certification common mistakes (April 14, 2022)
Docker 安裝 Redis
How to ensure the security of futures accounts online?
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
From introduction to mastery of MATLAB (2)
Calculation of fishing net road density
C medium? This form of
SSD硬盘SATA接口和M.2接口区别(详细)总结
Flash operates on multiple databases
Map basemap Library
Notepad + + replaces tabs with spaces
Cygwin64 right click to add menu, and open cygwin64 here
Custom prompt box MessageBox in QT
Refcell in rust
Daily CISSP certification common mistakes (April 12, 2022)
How to install jsonpath package
C language to achieve 2048 small game direction merging logic
QT reading and writing XML files (including source code + comments)
Queue solving Joseph problem
STM32学习记录0008——GPIO那些事1