当前位置:网站首页>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函数的学习
边栏推荐
- Oracle modify database character set
- Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
- Activity的创建和跳转
- Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
- Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
- [go practical basis] how to install and use gin
- Microservice practice | load balancing component and source code analysis
- MySql报错:unblock with mysqladmin flush-hosts
- 每天睡觉前30分钟阅读_day3_Files
- Amq6126 problem solving ideas
猜你喜欢

Microservice practice | declarative service invocation openfeign practice

Microservice practice | load balancing component and source code analysis

Don't look for it. All the necessary plug-ins for Chrome browser are here

Micro service practice | introduction and practice of zuul, a micro service gateway

微服务实战|声明式服务调用OpenFeign实践

图像识别-数据增广

Redis installation and deployment (windows/linux)

Chrome user script manager tempermonkey monkey

Break the cocoon | one article explains what is the real cloud primordial

Chrome video download Plug-in – video downloader for Chrome
随机推荐
Demand delineation executive summary
BugkuCTF-web16(备份是个好习惯)
自定義Redis連接池
企业级SaaS CRM实现
一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
Pool de connexion redis personnalisé
In depth analysis of how the JVM executes Hello World
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
JVM指令助记符
Microservice practice | teach you to develop load balancing components hand in hand
Creation and jump of activity
数构(C语言)——第四章、矩阵的压缩存储(下)
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
web安全与防御
[go practical basis] how to customize and use a middleware in gin
kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
Bold prediction: it will become the core player of 5g
微服务实战|手把手教你开发负载均衡组件
Safety production early warning system software - Download safety production app software
I've taken it. MySQL table 500W rows, but someone doesn't partition it?