Why Does Qt Use Moc for Signals and Slots(QT官方的解释:GUI可以是动态的)

GUIs are Dynamic

C++ is a standarized, powerful and elaborate general-purpose language. It‘s the only language that is exploited on such a wide range of software projects, spanning every kind of application from entire operating systems, database servers and high end graphics applications to common desktop applications. One of the keys to C++‘s success is its scalable language design that focuses on maximum performance and minimal memory consumption whilst still maintaining ANSI C compatibility.

For all these advantages, there are some downsides. For C++, the static object model is a clear disadvantage over the dynamic messaging approach of Objective C when it comes to component-based graphical user interface programming. What‘s good for a high end database server or an operating system isn‘t necessarily the right design choice for a GUI frontend. With moc, we have turned this disadvantage into an advantage, and added the flexibility required to meet the challenge of safe and efficient graphical user interface programming.

Our approach goes far beyond anything you can do with templates. For example, we can have object properties. And we can have overloaded signals and slots, which feels natural when programming in a language where overloads are a key concept. Our signals add zero bytes to the size of a class instance, which means we can add new signals without breaking binary compatibility.

Another benefit is that we can explore an object‘s signals and slots at runtime. We can establish connections using type-safe call-by-name, without having to know the exact types of the objects we are connecting. This is impossible with a template based solution. This kind of runtime introspection opens up new possibilities, for example GUIs that are generated and connected from Qt Designer‘s XML UI files.

http://doc.qt.io/qt-5/why-moc.html

时间: 2024-10-11 05:49:11

Why Does Qt Use Moc for Signals and Slots(QT官方的解释:GUI可以是动态的)的相关文章

Qt笔记——MOC(元对象编译器)

moc 全称是 Meta-Object Compiler,也就是"元对象编译器".Qt 程序在交由标准编译器编译之前,先要使用 moc 分析 C++ 源文件.如果它发现在一个头文件中包含了宏 Q_OBJECT,则会生成另外一个 C++ 源文件.这个源文件中包含了 Q_OBJECT 宏的实现代码.这个新的文件名字将会是原文件名前面加上 moc_ 构成.这个新的文件同样将进入编译系统,最终被链接到二进制代码中去.因此我们可以知道,这个新的文件不是"替换"掉旧的文件,而是

Dynamic Signals and Slots

Ref https://doc.qt.io/archives/qq/qq16-dynamicqobject.html Trolltech | Documentation | Qt Quarterly Dynamic Signals and Slotsby Eskil Abrahamsen Blomfeldt Signals and slots are declared at compile-time, and normally you cannot add new signals and slo

qt之旅-1纯手写Qt界面

通过手写qt代码来认识qt程序的构成,以及特性.设计一个查找对话框.下面是设计过程 1 新建一个empty qt project 2 配置pro文件 HEADERS += Find.h QT += widgets SOURCES += Find.cpp main.cpp 3 编写对话框的类 代码如下: //Find.h #ifndef FIND_H #define FIND_H #include <QDialog> class QCheckBox; class QLabel; class QL

Qt DLL总结【三】-VS2008+Qt 使用QPluginLoader访问DLL

目录 Qt DLL总结[一]-链接库预备知识 Qt DLL总结[二]-创建及调用QT的 DLL Qt DLL总结[三]-VS2008+Qt 使用QPluginLoader访问DLL 开发环境:VS2008.Qt4.7.4,附件有源码可供下载 最近在总结如何访问DLL中的类对象及其成员函数,其中一种方法利用Qt的QPluginLoader类就可以方便快捷的访问DLL中的类,以及其中的类成员函数. 文件结构如下图: 解决方案名:TestPlugin 1.Qt的Library项目(PluginDll)

QT开发(三十四)——QT多线程编程

QT开发(三十四)--QT多线程编程 一.QT多线程简介 QT通过三种形式提供了对线程的支持,分别是平台无关的线程类.线程安全的事件投递.跨线程的信号-槽连接. QT中线程类包含如下: QThread 提供了开始一个新线程的方法    QThreadStorage 提供逐线程数据存储    QMutex 提供相互排斥的锁,或互斥量    QMutexLocker 是一个辅助类,自动对 QMutex 加锁与解锁    QReadWriterLock 提供了一个可以同时读操作的锁    QReadL

mingw qt(可以去掉mingwm10.dll、libgcc_s_dw2-1.dll、libstdc++-6.dll的依赖,官方的mingw默认都是动态链接gcc的库而TDM是静态链接gcc库,tdm版本更好用)

原文地址:mingw qt作者:孙1东 不使用Qt SDK,使用mingw编译qt源代码所遇问题及解决方法: configure -fast -release -no-exceptions -no-rtti -no-stl -no-qt3support -no-opengl -no-multimedia -no-webkit -no-script -no-scripttools -nomake tools -nomake examples -nomake demos -nomake docs -

Qt 类外调用一个 private slots 函数

MainWindow中 private slots 函数 void print_on_log(QString strtemp);输出一个字符串到编辑窗口中 class MainWindow:publicQMainWindow {Q_OBJECTpublic:explicitMainWindow(QWidget*parent=0);~MainWindow();privateslots:voidprint_on_log(QStringstrtemp); 定义一个新类Test_one在此类中调用上面的

QT开发(六十五)——QT样式表编程实例

QT开发(六十五)--QT样式表编程实例 一.QComboBox组合框样式定制 1.基本定义 QComboBox  {     border: 1px solid gray;     border-radius: 3px;     padding: 1px 2px 1px 2px;  # 针对于组合框中的文本内容     min-width: 9em;   # 组合框的最小宽度 } QComboBox::drop-down {     subcontrol-origin: padding;   

常见的几个Qt编程问题的处理(转自QT中文论坛)(挺实用的)

1.如何在窗体关闭前自行判断是否可关闭答:重新实现这个窗体的closeEvent()函数,加入判断操作 void MainWindow::closeEvent(QCloseEvent*event){if (maybeSave()){writeSettings();event->accept();}else{event->ignore();}} 2.如何用打开和保存文件对话答:使用QFileDialog QString fileName = QFileDialog::getOpenFileNam