moc

How to add specific flags to moc in a qmake project?

依然范特西╮ 提交于 2019-11-29 10:02:55
I compile a Qt executable using qmake && make on the following project.pro file: INCLUDEPATH *= ../../dependencies/boost QT *= opengl xml CONFIG *= qt opengl static TARGET = myexe HEADERS = Viewer.hpp MainWindow.hpp Inspector.hpp SOURCES = main.cpp Viewer.cpp MainWindow.cpp Inspector.cpp However, when compiling, moc chokes on a boost macro which it cannot parse. To work around this bug , I need to pass the flag -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED to moc, but I cannot manage to do so. How to I edit my .pro file to pass a given flag to moc ? (but not to g++ , as QMAKE_CXXFLAGS does) A bit

Qt高级——Qt信号槽机制源码解析

﹥>﹥吖頭↗ 提交于 2019-11-29 09:41:14
一、信号槽机制的原理 1、信号槽简介 信号槽是观察者模式的一种实现,特性如下: A、一个信号就是一个能够被观察的事件,或者至少是事件已经发生的一种通知; B、一个槽就是一个观察者,通常就是在被观察的对象发生改变的时候——也可以说是信号发出的时候——被调用的函数; C、信号与槽的连接,形成一种观察者-被观察者的关系; D、当事件或者状态发生改变的时候,信号就会被发出;同时,信号发出者有义务调用所有注册的对这个事件(信号)感兴趣的函数(槽)。 信号和槽是多对多的关系。一个信号可以连接多个槽,而一个槽也可以监听多个信号。 信号槽与语言无关,有多种方法可以实现信号槽,不同的实现机制会导致信号槽的差别很大。信号槽术语最初来自 Trolltech 公司的 Qt 库,由于其设计理念的先进性,立刻引起计算机科学界的注意,提出了多种不同的实现。目前,信号槽依然是 Qt 库的核心之一,其他许多库也提供了类似的实现,甚至出现了一些专门提供这一机制的工具库。 信号槽是Qt对象以及其派生类对象之间的一种高效通信接口,是Qt的核心特性,也是Qt区别与其他工具包的重要地方。信号槽完全独立于标准的C/C++语言,因此要正确的处理好信号和槽,必须借助于一个成为MOC(Meta Object Compiler)的Qt工具,MOC工具是一个C++预处理程序,能为高层次的事件处理自动生成所需要的附加代码。 2

Could I have copy constructor for subclass of QObject?

拜拜、爱过 提交于 2019-11-28 11:37:31
Here we can read that no copy construct and copy assignment operator evaluable. But here we can read that qRegisterMetaType and Q_DECLARE_METATYPE have to have public default constructor, public copy constructor and public destructor. The question is: who is telling a lie? Or I did not understand it correctly? Ezee Everything is true: 1. QObject can't be copied and all its descendants can't be copied also. 2. Q_DECLARE_METATYPE accepts objects with public constructor, copy constructor and destructor. There is no contradiction, because you can't register QObject descendants with Q_DECLARE

Q_OBJECT or not Q_OBJECT

喜夏-厌秋 提交于 2019-11-28 08:58:38
问题 I wrote a little program with a my own class within the main.cpp. Here the code: #include <QApplication> #include <QPushButton> #include <QLabel> class MyWidget : public QWidget { //Q_OBJECT public: MyWidget(QWidget* parent = 0); QLabel* label; QString string; signals: public slots: void setTextLabel(); }; void MyWidget::setTextLabel() { label->setText("Test"); } MyWidget::MyWidget(QWidget* parent) : QWidget(parent) { } int main(int argc, char** argv) { QApplication app(argc, argv); MyWidget

How to add specific flags to moc in a qmake project?

不羁岁月 提交于 2019-11-28 03:24:32
问题 I compile a Qt executable using qmake && make on the following project.pro file: INCLUDEPATH *= ../../dependencies/boost QT *= opengl xml CONFIG *= qt opengl static TARGET = myexe HEADERS = Viewer.hpp MainWindow.hpp Inspector.hpp SOURCES = main.cpp Viewer.cpp MainWindow.cpp Inspector.cpp However, when compiling, moc chokes on a boost macro which it cannot parse. To work around this bug, I need to pass the flag -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED to moc, but I cannot manage to do so. How to I

Qt moc with implementations inside of header files?

╄→гoц情女王★ 提交于 2019-11-27 09:03:44
Is it possible to tell the Qt MOC that I would like to declare the class and implement it in a single file rather than splitting them up into an .h and .cpp file? If you want to declare and implement a QObject subclass in you cpp file, you have to manually include the moc file. For example: (file main.cpp) struct SubObject : QObject { Q_OBJECT }; //... #include "main.moc" You have to rerun moc ( make qmake ) after adding the #include statement. Kuba Ober TL;DR Yes, if you're talking only about the files that you write yourself (as opposed as those generated by moc). You don't need to do

Why is important to include “.moc” file at end of a Qt Source code file?

怎甘沉沦 提交于 2019-11-27 02:09:50
Why is it important to add an include for .moc file in a Qt cpp source code? This is a common step used in several Qt samples, including this one: http://doc.qt.io/qt-5/qttestlib-tutorial1-example.html ; where the line #include "testqstring.moc" should be included in the end of the file. I don't understand exactly why this is necessary. Thanks. It's necessary if you define QObject subclasses with the Q_OBJECT macro in a .cpp file. When you do so: qmake must generate rules inside your Makefile to invoke moc on that .cpp file. That special (hackish?) inclusion triggers qmake to do so, and tells

Qt moc with implementations inside of header files?

心已入冬 提交于 2019-11-26 14:28:23
问题 Is it possible to tell the Qt MOC that I would like to declare the class and implement it in a single file rather than splitting them up into an .h and .cpp file? 回答1: If you want to declare and implement a QObject subclass in you cpp file, you have to manually include the moc file. For example: (file main.cpp) struct SubObject : QObject { Q_OBJECT }; //... #include "main.moc" You have to rerun moc ( make qmake ) after adding the #include statement. 回答2: TL;DR Yes, if you're talking only

Why is important to include “.moc” file at end of a Qt Source code file?

旧街凉风 提交于 2019-11-26 12:32:38
问题 Why is it important to add an include for .moc file in a Qt cpp source code? This is a common step used in several Qt samples, including this one: http://doc.qt.io/qt-5/qttestlib-tutorial1-example.html; where the line #include \"testqstring.moc\" should be included in the end of the file. I don\'t understand exactly why this is necessary. Thanks. 回答1: It's necessary if you define QObject subclasses with the Q_OBJECT macro in a .cpp file. When you do so: qmake must generate rules inside your