当前位置:网站首页>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 use pyqt5 to make a sensitive word detection tool
- Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime
- 每天睡觉前30分钟阅读_day3_Files
- Chrome browser tag management plug-in – onetab
- Activity的创建和跳转
- Attributes of classfile
- Watermelon book -- Chapter 5 neural network
- 微服务实战|Eureka注册中心及集群搭建
- Microservice practice | declarative service invocation openfeign practice
- Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
猜你喜欢

Read 30 minutes before going to bed every day_ day4_ Files

Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)

Enterprise level SaaS CRM implementation

Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime

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

Idea view bytecode configuration

Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)

Activity的创建和跳转

企业级SaaS CRM实现

From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
随机推荐
微服务实战|Eureka注册中心及集群搭建
Mysql 多列IN操作
互联网API接口幂等设计
BugkuCTF-web16(备份是个好习惯)
From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
[go practical basis] how can gin get the request parameters of get and post
别找了,Chrome浏览器必装插件都在这了
Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
C语言之判断直角三角形
CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
Matplotlib swordsman line - layout guide and multi map implementation (Updated)
个人经历&&博客现状
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
[go practical basis] how to customize and use a middleware in gin
What are the differences between TP5 and laravel