- 浏览: 267717 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (156)
- Qt (21)
- C++ (10)
- javascript (8)
- linux (8)
- RTC (1)
- JNI (1)
- Qt 图形 (1)
- Mac Bootcamp (1)
- node.js (3)
- Windows SDK 7.1 (1)
- VS2010 (2)
- linux Tcl 脚本语言 (0)
- Mac (1)
- Clucene VS2013 (1)
- VisualStudio (1)
- golang (12)
- postgresql (5)
- SVN (1)
- VS (2)
- 微信开发 (8)
- html5 (1)
- Win7 (1)
- Office (1)
- redis (1)
- Bootstrap (1)
- nginx (2)
- docker (1)
- xorm (3)
- blender (2)
- linux ec2 (1)
- aws (1)
- 七牛云 (1)
- css (5)
- h2 (1)
- react (2)
- java (2)
- html (2)
- eclipse (1)
- java swing (1)
- webpack (1)
- mysql (5)
- VS2017 (1)
- 网站 (1)
- tomcat spring (1)
- Ant (2)
- sql (1)
- 其它 (1)
- Win10 (1)
- R (1)
- git (1)
- Windows (1)
- ubuntu (2)
- python (3)
- win 11 (1)
- quasar (1)
- github (1)
- protobuf (0)
- c# (1)
最新评论
(原文地址:https://code.google.com/p/qextserialport/wiki/Three_Usage_Of_MOC)
Three_Usage_Of_MOC
Updated Jan 30, 2013 by dbzhang...@gmail.com
All the developers of Qt should have been familiar with normal usage of MOC.
How to use moc(1)
Consider that we have a Qt project, which contains a subclass of QObject, and the definition of the class is in a header file.
// myclass.h
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass();
};
When qmake is running, once it find macro Q_OBJECT in header file, it will call moc for us.
moc myclass.h -o moc_myclass.cpp
As moc_myclass.cpp is a compile unit, so qmake will run compiler to compile it, then link the moc_myclass.o(bj) to other part. All of them are transparent for users.
g++ moc_myclass.cpp -o moc_myclass.o
How to use moc(2)
What will happen if the definition of the class located in one .cpp source file?
// main.cpp
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(){}
};
int main(int argc, char**argv)
{
...
}
When qmake is running, once it find macro Q_OBJECT in source file, it will call moc for us too.
moc main.cpp -o main.moc
Then what's the difference?
main.moc is not a compile unit any, as it will dependent on the definition of class MyClass.So it can not include the file "main.cpp".
# This will fail ....
g++ main.moc -o main_moc.o
How to solve this?
//Add following line to main.cpp file, after the definition of MyClass
#include "main.moc"
How to use moc(3)
If you have read the source code of qextserialport, you will find that
QextSerialPort defined in the header file qextserialport.h
But qextserialport.cpp contains following line
#include "moc_qextserialport.cpp"
So, when qmake is running, once it find macro Q_OBJECT in header file, it will call moc for us.
moc myclass.h -o moc_myclass.cpp
But, why we include "moc_qextserialport.cpp" manully?
In order to move private data member and private slots to non-public files, d-pointer and Q_PRIVATE_SLOT are used.
So the generated moc_qextserialport.cpp is dependent on non-public files will make it can not be compiled as a compile unit.
# This doesn't work any more ;-)
g++ moc_qextserialport.cpp -o moc_qextserialport.o
why both moc_xxx.cpp and xxx.moc exist?
In same cases, both myclass.h and myclass.cpp may have Q_OBJECT
// myclass.h
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass();
};
// myclass.cpp
class MyClassHelper : public QObject
{
Q_OBJECT
public:
MyClassHelper();
};
MyClass::MyClass()
{
}
...
In such cases, moc will generated two files for us
moc myclass.h -o moc_myclass.cpp
moc myclass.cpp -o myclass.moc
Three_Usage_Of_MOC
Updated Jan 30, 2013 by dbzhang...@gmail.com
All the developers of Qt should have been familiar with normal usage of MOC.
How to use moc(1)
Consider that we have a Qt project, which contains a subclass of QObject, and the definition of the class is in a header file.
// myclass.h
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass();
};
When qmake is running, once it find macro Q_OBJECT in header file, it will call moc for us.
moc myclass.h -o moc_myclass.cpp
As moc_myclass.cpp is a compile unit, so qmake will run compiler to compile it, then link the moc_myclass.o(bj) to other part. All of them are transparent for users.
g++ moc_myclass.cpp -o moc_myclass.o
How to use moc(2)
What will happen if the definition of the class located in one .cpp source file?
// main.cpp
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(){}
};
int main(int argc, char**argv)
{
...
}
When qmake is running, once it find macro Q_OBJECT in source file, it will call moc for us too.
moc main.cpp -o main.moc
Then what's the difference?
main.moc is not a compile unit any, as it will dependent on the definition of class MyClass.So it can not include the file "main.cpp".
# This will fail ....
g++ main.moc -o main_moc.o
How to solve this?
//Add following line to main.cpp file, after the definition of MyClass
#include "main.moc"
How to use moc(3)
If you have read the source code of qextserialport, you will find that
QextSerialPort defined in the header file qextserialport.h
But qextserialport.cpp contains following line
#include "moc_qextserialport.cpp"
So, when qmake is running, once it find macro Q_OBJECT in header file, it will call moc for us.
moc myclass.h -o moc_myclass.cpp
But, why we include "moc_qextserialport.cpp" manully?
In order to move private data member and private slots to non-public files, d-pointer and Q_PRIVATE_SLOT are used.
So the generated moc_qextserialport.cpp is dependent on non-public files will make it can not be compiled as a compile unit.
# This doesn't work any more ;-)
g++ moc_qextserialport.cpp -o moc_qextserialport.o
why both moc_xxx.cpp and xxx.moc exist?
In same cases, both myclass.h and myclass.cpp may have Q_OBJECT
// myclass.h
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass();
};
// myclass.cpp
class MyClassHelper : public QObject
{
Q_OBJECT
public:
MyClassHelper();
};
MyClass::MyClass()
{
}
...
In such cases, moc will generated two files for us
moc myclass.h -o moc_myclass.cpp
moc myclass.cpp -o myclass.moc
发表评论
-
&QComboBox::currentIndexChanged无法用于connect
2022-07-20 15:25 365改为如下 QObject::connect(comboBo ... -
Qt无法进入槽函数( the slot function cannot entry for Qt)
2022-07-05 22:37 1013如果connect没问题则需要检查一下信号发出者是否是在工 ... -
QtConcurrent::mappedReduced使用仿函数(functor)
2022-04-11 12:38 497参考https://stackoverflow.com/qu ... -
Qt open file report error "Broken filename passed to function"
2022-02-18 15:22 593原因: 文件名的最后多了一个\0会导致这个错误 -
QPainter在4K屏上绘制不清楚 (QPainter not clear in high DPI)
2021-12-31 10:23 927如果是先将内容绘制到一个图片缓存上的话,这个图片缓存需要放 ... -
Qt开发磁盘空间查看器
2021-09-09 10:30 0int main(int argc, char **argv ... -
QTableWidget的openPersistentEditor去掉高亮选择
2021-08-02 10:59 571如果用QTableWidget作为一个表格编辑控件的话,简单 ... -
qt安装包制作前的依赖文件收集
2019-05-16 14:29 632将***.exe文件copy到一个空的bin目录下,然后命令行 ... -
QListView实现流式布局和多列效果(flow layout and multiple columns)
2017-10-31 10:49 2556关键的三个调用: 1. setViewMode(QLis ... -
VS2010 如何调试进(step into)项目引用的第三方开源源代码,比如Qt源码
2015-01-07 09:06 1714在Solution上点击右键,选择"Properti ... -
Qt Creator配置vs2010编译器和调试器
2014-10-14 00:20 9587(本文系原创,转载请 ... -
QT间进程通信之共享内存
2014-07-18 11:28 0QT间进程通信之共享内存 Qt提供了一种安全的共享内存 ... -
Qt相关一个编译错误:'staticMetaObject' is not a member of ‘XXXClass’
2013-11-21 10:45 1349这个错误是怎么引起的呢?就是如果一个类不是从QObject及其 ... -
foreach的元素是QPair之类具有逗号的类型怎么办?
2013-05-30 19:41 1090如上所述: foreach(QPair<int,QStr ... -
qmake 提示"has modification time 1.9e+07 s in the future"
2013-04-07 10:49 1778qmake有个要求就是它的pro文件的修改时间必须早于系统时间 ... -
QGraphicsWidget的geometry和boundingRect是什么关系?
2012-12-25 17:08 1560QGraphicsWidget的boundingRect的概念 ... -
QWebPage的linkClicked无效?
2012-07-22 16:53 1212调用一下QWebPage实例的setLinkDelegatio ... -
Qt 插件编译可过但加载失败时提示undefined symbol
2011-12-30 11:23 2043查一下是不是需要moc的头文件没有加入工程文件,在pro里HE ... -
Qt 国际化翻译失败的一个原因
2011-12-24 21:57 1926(本文系原创,如需转载请标明来自http://johnsmit ... -
Qt Style 大全
2011-12-06 18:19 942http://www.cppblog.com/seahouse ...
相关推荐
MOC3061 是一种过零触发双硅输出光耦,由 MOTOROLA 公司生产,广泛应用于触发晶闸管。该器件具有价格低廉、触发电路简单可靠的特点。 内部结构及主要性能参数: MOC3061 采用双列直插 6 脚封装。其主要性能参数为:...
MOC是一种解决偏微分方程,特别是流体动力学中如连续性方程、动量方程和能量方程的方法。在喷嘴设计中,这一技术用于精确地模拟流体流动,特别是在高速或超音速流动条件下,如火箭发动机或喷气飞机的喷嘴设计。 MOC...
MOC3061是一种光耦合器,用于电气隔离和信号传输,特别是在高压或高噪声环境中,它的优势尤为明显。MOC3061内部集成了一个发光二极管(LED)和一个光敏双向可控硅,这使得它能够在电气上隔离两个电路的同时,通过光...
"MOC"通常代表"Method of Characteristics",这是一种解决偏微分方程,特别是流体力学中的超音速流动问题的数值方法。Moc4455可能是这个特定实现的版本号或者项目标识。 在描述中,"使用特征方法进行流过喷管的超...
文件“moc.m”是使用MATLAB编写的MOC算法实现代码,通过这个代码,我们可以进一步理解MOC方法在泡沫驱替模拟中的具体操作和计算流程。通过运行和分析代码,不仅可以验证理论的理解,还可以为实际油藏模拟提供参考。 ...
### Qt MOC 处理器 UML 图解析 ...以上内容详细描述了 Qt MOC 处理器 UML 图中涉及的主要元素和它们的属性与方法。这些元素和结构共同构成了 Qt MOC 的内部架构,有助于开发者深入了解 MOC 如何处理和生成元数据。
1. **动态链接库(DLL)嵌入**:`DsoFramer`允许开发者将DLL功能集成到他们的应用程序中,提供了一种方便的方式来使用外部代码,减少内存占用,提高代码重用。 2. **COM对象交互**:`DsoFramer`支持COM对象,这意味...
使用MF14型三用表(多功能电表)在DC挡进行检测,可以获取MOC8106TV的工作电压等关键参数。这些数据对于判断器件是否正常工作至关重要。具体检测数据通常包括输入电压、输出电流、光耦合效率等。在索尼CPD-200GS型...
特征线法,也称为MOC(Method of Characteristics),是一种在流体力学中广泛使用的数值方法,主要用于求解一维非稳态流动问题,包括管道中的压力和流量问题。本主题聚焦于如何应用特征线法来解决包含动态摩阻的管道...
MOC方法是一种高效的中子输运方程求解手段,它通过将三维问题转化为多维问题来处理。这种方法在堆芯物理数值计算中尤为关键,但其计算过程中包含大量的数值积分和矩阵运算,导致计算量庞大,传统CPU难以满足日益增长...
标题"MOC_1300m_20dgree_70dgree_管道流MATLAB_管道计算_matlab_"表明这是一个使用MATLAB编程环境进行的管道流动模拟项目,其中"1300m"可能代表管道的长度,"20dgree"和"70dgree"可能是温度条件,可能涉及不同温度下...
在本项目中,我们探讨了如何使用特性方法(Method of Characteristics, MOC)来设计一个二维平面的最小长度钟形喷嘴。Matlab作为一种强大的数值计算工具,被用来实现这一复杂的设计过程。以下是对该主题的详细解释:...
MOC方法是一种广泛应用于核反应堆设计、安全分析及性能评估的数值计算技术,它通过随机漫步模拟中子在材料中的传输过程。 首先,CPU-GPU异构并行计算的基本原理是将计算任务分配到两种不同类型的处理器上。CPU擅长...
- **恢复模式**:介绍了三种不同的恢复模式(简单、完整、大容量日志记录)及其适用场景。 - **灾难恢复计划**:指导如何制定有效的灾难恢复计划以确保业务连续性。 ### 模块7:基本管理 - **服务器安装**:讲解了...
这个名为"moc.v1.0.rc1.2009.05.03.src.zip"的压缩包,包含了用于Ogre引擎的碰撞检测工具,旨在简化开发者的操作,提供了一种高效的小型引擎组件。 该压缩包中的核心文件是"CollisionTools.cpp"和"CollisionTools.h...
【标题】"Microsoft MOC 2555 - Windows Applications Using C#" 这门课程主要聚焦于使用C#编程语言开发Windows应用程序。MOC(Microsoft Official Curriculum)是微软官方提供的培训课程,旨在帮助开发者深入理解...
正确的方法是将MOC3061放置在G极与T2之间,这样当控制信号使G极与T2之间产生电压差时,可控硅才会导通。 MOC3061推荐的电路图显示,G极是从T1引出,光耦合器位于G极与T2之间。理解这一点至关重要,因为它揭示了G极...
本文将重点介绍Qt中的第三方日志库qslog的配置和使用方法,以帮助开发者更好地理解和应用到实际项目中。 首先,qslog是一个轻量级的日志库,它为Qt应用程序提供了丰富的日志记录功能,支持多种输出方式,如控制台...
《担载型MoC催化剂的制备和催化剂加氢转化反应性能研究》这篇学年论文主要探讨了二氧化碳的处理和转化技术,特别是通过担载型MoC催化剂进行加氢转化制备甲醇的过程。二氧化碳作为一种温室气体,其排放量的增长对全球...