当前位置:网站首页>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函数的学习
边栏推荐
- 个人经历&&博客现状
- 因上努力,果上随缘
- Microservice practice | fuse hytrix initial experience
- Knife4j 2. Solution to the problem of file control without selection when uploading x version files
- Thinkphp5 how to determine whether a table exists
- c语言编程题
- FragmentTabHost实现房贷计算器界面
- 微服务实战|微服务网关Zuul入门与实战
- 自定义Redis连接池
- 攻防世界-Web进阶区-unserialize3
猜你喜欢

Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程

数构(C语言)——第四章、矩阵的压缩存储(下)

一篇详解带你再次重现《统计学习方法》——第二章、感知机模型

Solutions to Chinese garbled code in CMD window

BugkuCTF-web24(解题思路及步骤)

Actual combat of microservices | discovery and invocation of original ecosystem implementation services

Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue

Typeerror: X () got multiple values for argument 'y‘

hystrix 实现请求合并

web安全与防御
随机推荐
道阻且长,行则将至
Chrome浏览器标签管理插件–OneTab
"Interview high frequency question" is 1.5/5 difficult, and the classic "prefix and + dichotomy" application question
数构(C语言)——第四章、矩阵的压缩存储(下)
Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
Chrome video download Plug-in – video downloader for Chrome
微服务实战|负载均衡组件及源码分析
上班第一天的报错(AWVS卸载不彻底)
微服务实战|微服务网关Zuul入门与实战
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
Microservice practice | Eureka registration center and cluster construction
Oracle delete tablespace and user
What are the differences between TP5 and laravel
MySQL multi column in operation
Enterprise level SaaS CRM implementation
自定义Redis连接池
Fragmenttabhost implements the interface of housing loan calculator
MySQL事务
互联网API接口幂等设计
[go practical basis] how to install and use gin