- 浏览: 252334 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (152)
- 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 (11)
- 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)
最新评论
(原文地址: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 232改为如下 QObject::connect(comboBo ... -
Qt无法进入槽函数( the slot function cannot entry for Qt)
2022-07-05 22:37 668如果connect没问题则需要检查一下信号发出者是否是在工 ... -
QtConcurrent::mappedReduced使用仿函数(functor)
2022-04-11 12:38 358参考https://stackoverflow.com/qu ... -
Qt open file report error "Broken filename passed to function"
2022-02-18 15:22 487原因: 文件名的最后多了一个\0会导致这个错误 -
QPainter在4K屏上绘制不清楚 (QPainter not clear in high DPI)
2021-12-31 10:23 700如果是先将内容绘制到一个图片缓存上的话,这个图片缓存需要放 ... -
Qt开发磁盘空间查看器
2021-09-09 10:30 0int main(int argc, char **argv ... -
QTableWidget的openPersistentEditor去掉高亮选择
2021-08-02 10:59 412如果用QTableWidget作为一个表格编辑控件的话,简单 ... -
qt安装包制作前的依赖文件收集
2019-05-16 14:29 567将***.exe文件copy到一个空的bin目录下,然后命令行 ... -
QListView实现流式布局和多列效果(flow layout and multiple columns)
2017-10-31 10:49 2372关键的三个调用: 1. setViewMode(QLis ... -
VS2010 如何调试进(step into)项目引用的第三方开源源代码,比如Qt源码
2015-01-07 09:06 1664在Solution上点击右键,选择"Properti ... -
Qt Creator配置vs2010编译器和调试器
2014-10-14 00:20 9528(本文系原创,转载请 ... -
QT间进程通信之共享内存
2014-07-18 11:28 0QT间进程通信之共享内存 Qt提供了一种安全的共享内存 ... -
Qt相关一个编译错误:'staticMetaObject' is not a member of ‘XXXClass’
2013-11-21 10:45 1253这个错误是怎么引起的呢?就是如果一个类不是从QObject及其 ... -
foreach的元素是QPair之类具有逗号的类型怎么办?
2013-05-30 19:41 1038如上所述: foreach(QPair<int,QStr ... -
qmake 提示"has modification time 1.9e+07 s in the future"
2013-04-07 10:49 1593qmake有个要求就是它的pro文件的修改时间必须早于系统时间 ... -
QGraphicsWidget的geometry和boundingRect是什么关系?
2012-12-25 17:08 1514QGraphicsWidget的boundingRect的概念 ... -
QWebPage的linkClicked无效?
2012-07-22 16:53 1152调用一下QWebPage实例的setLinkDelegatio ... -
Qt 插件编译可过但加载失败时提示undefined symbol
2011-12-30 11:23 1904查一下是不是需要moc的头文件没有加入工程文件,在pro里HE ... -
Qt 国际化翻译失败的一个原因
2011-12-24 21:57 1823(本文系原创,如需转载请标明来自http://johnsmit ... -
Qt Style 大全
2011-12-06 18:19 887http://www.cppblog.com/seahouse ...
相关推荐
使用特征方法进行流过喷管的超音速流的二维分析的JAVA源程序
Qt中第三方日志库qslog的基本配置和使用详解示例程序,可参考文章:https://blog.csdn.net/hp_cpp/article/details/123660840
设计马赫数、膨胀波数、比热比由用户提供。 文件planar_moc.m 生成特征网络和喷嘴轮廓。
信号和槽是 QT 自行定义的一种通信机制,它独立于标准的 C/C++ 语言,因此要正确的处理信号和槽,必须借助一个称为 moc(Meta Object Compiler)的 QT 工具,该工具是一个 C++ 预处理程序,它为高层次的事件处理自动...
Qt是面向对象的框架,使用特殊的代码生成扩展(称为元对象编译器(Meta Object Compiler, moc))以及一些宏,Qt很容易扩展,并且允许真正地组件编程。2008年,Qt Company科技被诺基亚公司收购,Qt也因此成为诺基亚...
开发厂商会推出一整套交叉编译工具链来配合自身的嵌入式产品,但是这些由商业公司提供的工具链,都不会附有工具链相关的源代码和制作方法,灵活性不足,并且它们一般都与整套开发系统捆绑销售使用,成本较高。
本文实例讲述了C#实现翻转字符串的方法。分享给大家供大家参考。具体实现方法如下: Func<string> ReverseString = delegate(string s) { char[] word = s.ToCharArray(); for (int i = 0, j = (s.Length - 1); i...
引力波电磁优化 该代码目前可以: 与 Gracedb 交互,下载天空图,阅读它们等。 读取包含位置、FOV、限制幅度、曝光时间等的望远镜配置文件。 根据望远镜配置(MOC,...更多详情、使用方法,请下载后阅读README.md文件
对于一个给定的字符串,逆序输出,这个任务对于python来说是一种很简单的操作,毕竟强大的列表和字符串处理的一些列函数足以应付这些问题 了,今天总结了一下python中对于字符串的逆序输出的几种常用的方法 方法一:...
如何对双向触发二极管进行检测,使用万用表检测双向触发二极管的方法简介
元对象系统moc(Meat-Object System)的对象MetaObject和(含动态)属性Propert的用法
使用方法类似Qt的信号槽,优点是不需要moc;基于c++11,用于解耦合;GOSP(GUI框架)以此信号槽为特色和基础; signal/slot which is Qt-Style, and not depends on moc
通过将动作实例视为移动点的轨迹,提出一种新的动作细管检测框架,称为“ MoveCenterCenter检测器”(MOC-detector) 。 MOC检测器被分解为三个关键的头分支: (1)中心分支,例如中心检测和动作识别。 (2)运动...
为了解决Qt信号槽(需要依赖moc机制和moc工具)的缺陷,我创造了本软件。 利用本软件,c++开发者可以在不依赖c++...开发者可以将本软件放到开发环境中去编译和运行,并配合《用户文档.doc》来学习本软件的使用方法。
在qt中可以直接添加信号与槽 在vs中使用是不一样的 直接新建一个qt 项目 打开 设计师界面 在vs中 的头文件中添加 槽函数 .cpp中实现 比较让人在意的是 构造函数中 ui.setupUi(this) 在qt中是ui->setupUi(this) 在...
轮播有几种形式, 比如常见的横向海报图片展示, 还有横纵向商品列表展示,头条信息框轮换 siwper组件很好的实现了横向海报图片展示,比如 头条信息框转换采用上下轮换, 使用scroll-view嵌套 1. 微信小程序的组件...
轮播有几种形式, 比如常见的横向海报图片展示, 还有横纵向商品列表展示,头条信息框轮换 siwper组件很好的实现了横向海报图片展示,比如 头条信息框转换采用上下轮换, 使用scroll-view嵌套 1. 微信小程序的组件...
不过本人在使用该种方法时kinect一直驱动不成功,即使用opencv的VideoCapture类来捕捉Kinect设备的数据,一直是打不开的,即驱动不成功。但是kinect设备已经连接上了,且能运行openni中的sample,说明kinect的硬件...
出于安全考虑,主要石油公司(MOC),港口国,船级社和船旗国增加了对油轮的检查次数。 由于密集的货运操作,油轮检查变得越来越困难和效率低下。 低效,主观或不合标准的检查/评估通常会导致错误的决定,并导致不...
Qt 是 1991 年由奇趣科技开发的跨平台 C++图形用户界面应用程序开发框架。... Qt 是面向对象的框架, 使用特殊的代码生成扩展(称为元对象编译器(Meta Object Compiler, moc)) 以及一些宏, 易于扩展, 允许组件编程。