当前位置:网站首页>Causes and solutions of QT signal and slot connection failure
Causes and solutions of QT signal and slot connection failure
2022-07-24 16:25:00 【User 6557940】
introduction
The signal and slot mechanism is Qt Important foundation , By connecting the signal to the slot , It can realize the logical connection between different operations 、 Parameter transmission and timely feedback . Sometimes the program compiles successfully , however connect There is no connection between signal and slot , Why is that ?
Qt The main reasons for the failure of signal and slot connection are as follows :
1. Slot function is not declared in class public slots( or private slots or protected slots) in , therefore , The function you want to be a slot function is just a general member function .
2. There is parameter transfer between the signal and the slot , But the number or type of parameters of the two are inconsistent ( The number of parameters in the signal can be more than that in the slot function , But both have parameters , The type must correspond to );
3. There is parameter transmission between the signal and the slot , But use connect When slot function or signal or both are added with formal parameters , For example, the following two connect, The first connection has formal parameters , Will not connect successfully . The second one will connect successfully .
///connect 1
connect(sender, SIGNAL(sendMessage(int a)), receiver, SLOT(getMessage(int b)));
///connect 2
connect(sender, SIGNAL(sendMessage(int)), receiver, SLOT(getMessage(int)));4. There is a custom parameter transfer between the signal and the slot , But the type passed is not registered . What is a custom parameter ? In passing int,double,char,bool,float It's OK to wait for the type , But delivery, such as QList class , Or a custom structure 、 Class isochronous , Connection will fail . The following error will be reported :
At this point, we need to register this custom type , First include the header file
// Add a file reference
#include <QMetaType>stay connect Previous registration :
// Register parameter type
qRegisterMetaType<QList<QString> > ("QList<double>");Then you can connect successfully !
边栏推荐
- Who is the "roll" king of the prefabricated vegetable track?
- Multithreading (basic)
- Disassembly of Samsung Galaxy fold: the interior is extremely complex. Is the hinge the main cause of screen damage?
- hping3安装使用
- Please talk about the financial products with a yield of more than 6%
- 287 finding duplicates
- If this.$router Push the same address with different parameters, and the page does not refresh
- The 3D sensing market is accelerating. Who will be better, TOF or structured light?
- TCP protocol debugging tool tcpengine v1.3.0 tutorial
- Code shoe set - mt2093 · palindrome digit
猜你喜欢

Servlet framework (servlet+jsp) + addition, deletion, modification and query + paging implemented by MySQL (function package student information entry, addition, deletion, modification and query of st

Leetcode 220. duplicate element III exists

2.19 haas506 2.0 development tutorial - Bluetooth - Bluetooth communication (only supports versions above 2.2)

Custom view - Custom button
![Programming in CoDeSys to realize serial communication [based on raspberry pie 4B]](/img/9c/05118efe2152dc5461a92720732076.jpg)
Programming in CoDeSys to realize serial communication [based on raspberry pie 4B]

Rest style

LaneATT

Knowledge points of MySQL (12)

REST风格

Power of leetcode 231.2
随机推荐
Using native JS to realize magnifying glass function
You really should go to the factory to move bricks!
After data management, the quality is still poor
Caikeng Alibaba cloud Kex_ exchange_ identification: read: Connection reset by peer
若依 this.$router.push 同地址不同参,页面不刷新问题
Power of leetcode 231.2
[leetcode]75. color classification - problem solving (execution time beat 90%, memory consumption beat 78%)
栈与队列——1047. 删除字符串中的所有相邻重复项
Software recommendation - office software
[leetcode] day103 search two-dimensional matrix II
1184. 公交站间的距离
Enter a URL to this page to show it. What happened in this process?
Qt设计仿真机器人控制器
ARP 入门
The 3D sensing market is accelerating. Who will be better, TOF or structured light?
Vscode common shortcut keys
2.19 haas506 2.0开发教程 - bluetooth - 蓝牙通信(仅支持2.2以上版本)
普林斯顿微积分读本02第一章--函数的复合、奇偶函数、函数图像
ZBar project introduction and installation configuration| [email protected]
Huawei Kirin 985 mass production in the third quarter: TSMC 7Nm EUV process, integrated 5g baseband!