当前位置:网站首页>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函数的学习
边栏推荐
- Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
- 破茧|一文说透什么是真正的云原生
- 分布式锁的这三种实现方式,如何在效率和正确性之间选择?
- C语言之分草莓
- Pool de connexion redis personnalisé
- Mysql 多列IN操作
- Say goodbye to 996. What are the necessary plug-ins in idea?
- 告别996,IDEA中必装插件有哪些?
- Alibaba /热门json解析开源项目 fastjson2
- 长篇总结(代码有注释)数构(C语言)——第四章、串(上)
猜你喜欢

Chrome浏览器标签管理插件–OneTab

Chrome user script manager tempermonkey monkey

DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!

Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc

Pool de connexion redis personnalisé

zk配置中心---Config Toolkit配置与使用

hystrix 实现请求合并

Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method

记录一下初次使用Xray的有趣过程

互联网API接口幂等设计
随机推荐
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
[go practical basis] how to verify request parameters in gin
一次聊天勾起的回忆
"Redis source code series" learning and thinking about source code reading
Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
Solution to amq4036 error in remote connection to IBM MQ
攻防世界-Web进阶区-unserialize3
Redis installation and deployment (windows/linux)
MySQL事务
C语言之判断直角三角形
Micro service practice | introduction and practice of zuul, a micro service gateway
每天睡觉前30分钟阅读_day4_Files
数构(C语言--代码有注释)——第二章、线性表(更新版)
微服务实战|手把手教你开发负载均衡组件
Demand delineation executive summary
图像识别-数据增广
How to choose between efficiency and correctness of these three implementation methods of distributed locks?
Break the cocoon | one article explains what is the real cloud primordial
C语言之做木桶
因上努力,果上随缘