当前位置:网站首页>QT信号槽总结-connect函数错误用法
QT信号槽总结-connect函数错误用法
2022-07-02 06:34:00 【懵懂的梦花火】
QT库的qobject.h
connect函数声明:connect函数用于建立信号与槽之间的连接,QT库提供了三种实现:
static QMetaObject::Connection connect(const QObject *sender, const char *signal,
const QObject *receiver, const char *member, Qt::ConnectionType = Qt::AutoConnection);
static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
const QObject *receiver, const QMetaMethod &method,
Qt::ConnectionType type = Qt::AutoConnection);
inline QMetaObject::Connection connect(const QObject *sender, const char *signal,
const char *member, Qt::ConnectionType type = Qt::AutoConnection) const;
class ConnectCamera : public QWidget
{
Q_OBJECT
public:
ConnectCamera(QWidget *parent = Q_NULLPTR);
~ConnectCamera();
public slots:
void onConnectBtnSolt();
void onCancelBtSolt();
void onErrorMess(const QString & _errorMess);
signals:
void signalConnectCamera(const QString& _ip, const QString& _user, const QString& _pass);
private:
Ui::ConnectCamera ui;
};
使用QT库提供的第一种实现方式,来绑定信号与槽
正确用法1:
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(onConnectBtnSolt()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(onCancelBtSolt()));
错误用法1:
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(onConnectBtnSolt));
原因分析:
用法1调用的connect函数实际为:
static QMetaObject::Connection connect(const QObject *sender, const char *signal,
const QObject *receiver, const char *member, Qt::ConnectionType = Qt::AutoConnection);
// SLOT的定义
Q_CORE_EXPORT const char *qFlagLocation(const char *method);
# define SLOT(a) qFlagLocation("1"#a QLOCATION)
qt中的信号槽,实际用的是回调函数,onConnectBtnSolt()被解析为函数,onConnectBtnSolt格式判断会出错
网上很详细的讲解,QT版本可能早于5.9.6
QT QObject::connect函数的学习
边栏推荐
- How to choose between efficiency and correctness of these three implementation methods of distributed locks?
- 西瓜书--第五章.神经网络
- C语言之最小数
- Read 30 minutes before going to bed every day_ day3_ Files
- 长篇总结(代码有注释)数构(C语言)——第四章、串(上)
- Matplotlib swordsman - a stylist who can draw without tools and code
- Methods of classfile
- Redis installation and deployment (windows/linux)
- Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
- Chrome用户脚本管理器-Tampermonkey 油猴
猜你喜欢
别找了,Chrome浏览器必装插件都在这了
西瓜书--第六章.支持向量机(SVM)
Chrome user script manager tempermonkey monkey
Typeerror: X () got multiple values for argument 'y‘
Idea view bytecode configuration
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
BugkuCTF-web24(解题思路及步骤)
数构(C语言)——第四章、矩阵的压缩存储(下)
微服务实战|负载均衡组件及源码分析
[go practical basis] how to set the route in gin
随机推荐
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
Watermelon book -- Chapter 5 neural network
Operation and application of stack and queue
C语言之分草莓
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
概念到方法,绝了《统计学习方法》——第三章、k近邻法
因上努力,果上随缘
VIM operation command Encyclopedia
微服务实战|负载均衡组件及源码分析
Customize redis connection pool
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
微服务实战|微服务网关Zuul入门与实战
MySQL error: unblock with mysqladmin flush hosts
Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
Insight into cloud native | microservices and microservice architecture
ClassFile - Attributes - Code
Flink - use the streaming batch API to count the number of words
Idea view bytecode configuration
Microservice practice | fuse hytrix initial experience
记录下对游戏主机配置的个人理解与心得