当前位置:网站首页>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
边栏推荐
- Crawling mobile game website game details and comments (MQ + multithreading)
- 【ACM】70. climb stairs
- Software test summary
- CISSP certified daily knowledge points (April 11, 2022)
- From source code to executable file
- Crawl the product data of Xiaomi Youpin app
- Rewrite four functions such as StrCmp in C language
- 7-21 wrong questions involve knowledge points.
- Rust: the output information of println is displayed during the unit test
- Calculation of fishing net road density
猜你喜欢
Calculation of fishing net road density
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
Robocode tutorial 5 - enemy class
【ACM】70. 爬楼梯
Dynamically add default fusing rules to feign client based on sentinel + Nacos
Batch export ArcGIS attribute table
mysql自动启动设置用Systemctl start mysqld启动
解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
硬核解析Promise對象(這七個必會的常用API和七個關鍵問題你都了解嗎?)
随机推荐
Rewrite four functions such as StrCmp in C language
According to the result set queried by SQL statement, it is encapsulated as JSON
C language to achieve 2048 small game direction merging logic
QT tablewidget insert qcombobox drop-down box
Correct opening method of option
线上怎么确定期货账户安全的?
Stm32mp157 wm8960 audio driver debugging notes
Function recursion and solving interesting problems
Install pyshp Library
函数递归以及趣味问题的解决
Robocode tutorial 7 - Radar locking
Gson fastjason Jackson of object to JSON difference modifies the field name
Rust: how to implement a thread pool?
Log4j2 cross thread print traceid
Robocode Tutorial 4 - robocode's game physics
word frequency count
Custom prompt box MessageBox in QT
Daily CISSP certification common mistakes (April 12, 2022)
CISSP certified daily knowledge points (April 11, 2022)
Solution to Chinese garbled code after reg file is imported into the registry