当前位置:网站首页>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函数的学习
边栏推荐
- I've taken it. MySQL table 500W rows, but someone doesn't partition it?
- Watermelon book -- Chapter 5 neural network
- Read 30 minutes before going to bed every day_ day4_ Files
- Thinkphp5 how to determine whether a table exists
- Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
- Typeerror: X () got multiple values for argument 'y‘
- MySQL error: unblock with mysqladmin flush hosts
- What is the function of laravel facade
- MySql报错:unblock with mysqladmin flush-hosts
- Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
猜你喜欢

Insight into cloud native | microservices and microservice architecture

互联网API接口幂等设计

zk配置中心---Config Toolkit配置与使用
![[go practical basis] how can gin get the request parameters of get and post](/img/fd/66074d157d93bcf20a5d3b37da9b3e.png)
[go practical basis] how can gin get the request parameters of get and post

图像识别-数据采集

Oracle modify database character set
![[go practical basis] how to install and use gin](/img/0d/3e899bf69abf4e8cb7e6a0afa075a9.png)
[go practical basis] how to install and use gin

Learn combinelatest through a practical example
![[go practical basis] how to bind and use URL parameters in gin](/img/63/84717b0da3a55d7fda9d57c8da2463.png)
[go practical basis] how to bind and use URL parameters in gin

Activity的创建和跳转
随机推荐
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
概念到方法,绝了《统计学习方法》——第三章、k近邻法
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
BugkuCTF-web21(详细解题思路及步骤)
Mysql 多列IN操作
VIM操作命令大全
西瓜书--第五章.神经网络
Who is better for Beijing software development? How to find someone to develop system software
Matplotlib剑客行——布局指南与多图实现(更新)
[go practical basis] how to verify request parameters in gin
自定義Redis連接池
MySql报错:unblock with mysqladmin flush-hosts
C语言之到底是不是太胖了
Chrome browser tag management plug-in – onetab
web安全与防御
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
Matplotlib swordsman - a stylist who can draw without tools and code
Matplotlib swordsman line - first acquaintance with Matplotlib
Oracle delete tablespace and user