每日一笔记之3:QTconnect()
2015-11-09 16:47
513 查看
刚学习QT的时候,跟着教程做一些简答的实验,教程简单的界面使用UI文件,直接在界面上拖一个按键,在右键go to slot,在编写槽函数。
我以前没学过C++,一直以为这个自动跳转过去的slot函数是一个虚函数,只是在这儿reinpliment而已。今天尝试自己通过纯代码编写,找了半天也没找到这个所谓的虚函数原型。
百度了才知道这个void on_pushbutton_clicked()不是已经声明的虚函数,而是按照这种格式写的函数不需要connect,用的是另外一个函数,在ui_mainwindow.h这个文件中,名字叫connectSlotsByName
详细说明:
void QMetaObject::connectSlotsByName ( QObject * object ) [static]
Searches recursively for all child objects of the given object, and connects matching signals from them to slots of object that follow the following form:
void on_<object name>_<signal name>(<signal parameters>);
Let's assume our object has a child object of type QPushButton with the object name button1. The slot to catch the button's clicked() signal would be:
void on_button1_clicked();
QMetaObject::connectSlotsByName(MainWindow);
大神们都不推荐这么使用。
我以前没学过C++,一直以为这个自动跳转过去的slot函数是一个虚函数,只是在这儿reinpliment而已。今天尝试自己通过纯代码编写,找了半天也没找到这个所谓的虚函数原型。
百度了才知道这个void on_pushbutton_clicked()不是已经声明的虚函数,而是按照这种格式写的函数不需要connect,用的是另外一个函数,在ui_mainwindow.h这个文件中,名字叫connectSlotsByName
详细说明:
void QMetaObject::connectSlotsByName ( QObject * object ) [static]
Searches recursively for all child objects of the given object, and connects matching signals from them to slots of object that follow the following form:
void on_<object name>_<signal name>(<signal parameters>);
Let's assume our object has a child object of type QPushButton with the object name button1. The slot to catch the button's clicked() signal would be:
void on_button1_clicked();
QMetaObject::connectSlotsByName(MainWindow);
大神们都不推荐这么使用。
相关文章推荐
- QT工具___语言翻译
- Qt 去除窗口阴影
- 环境 debian 8.2 (x86-64) 桌面环境cinnamon ibus安装
- 设置QT 无框架,,,无最小化,最大化
- 解决QT中中文乱码问题
- 通过QT 转换html文件为word文档
- qtablewidget 导出为 excel
- Qt发布程序(windows平台)
- QThread中的互斥、读写锁、信号量、条件变量
- Qt QTableWidget 和 QTableView
- Qt中的QString和QByteArray
- 使用Qt开发中国象棋(一):概述
- Qt入门1---widget、mainwindow和Dialog区别
- 使用Qt开发文本编辑器(一):功能介绍
- Qt中利用定时器QTimer准实时显示当前日期和时间
- Qt下数据库驱动查看程序
- Windows下Qt和Qwt的安装
- 关于vs2010+QT Addin 创建类时弹出"Not a valid .h file"的解决方法
- Qt改变tabWidget标题框背景
- Qt配置winCE环境中BUG总结