reduced no of files by optimising moc generation
This commit is contained in:
parent
0d10ad8215
commit
feef6c13b9
@ -187,7 +187,7 @@ Taking the example of QLabel, if you look inside the directory `src/cpp/QtWidget
|
||||
├── QLabel
|
||||
│ ├── nlabel.cpp
|
||||
│ ├── nlabel.h <---- Extended QLabel
|
||||
│ ├── nlabel_moc.h <--- Autogenerated file by qt moc.
|
||||
│ ├── nlabel_moc.cpp <--- Autogenerated file by qt moc.
|
||||
│ ├── qlabel_wrap.cpp
|
||||
│ └── qlabel_wrap.h <--- Wrapper file
|
||||
```
|
||||
@ -201,10 +201,10 @@ The idea is :
|
||||
So if you take a look at NLabel you will see, it inherits from QLabel and YogaWidget. It would in future inherit from more classes that implement event listeners etc. YogaWidget is a class that contains the magic that enables a regular Qt Widget to have Yoga node. A Yoga node is an instance used by yoga library to calculate a widgets position on the screen. Yoga is a library that will layout the widget on the screen. To do so we will specify the flex properties like alignitems, justify content, margin, paddings etc on the Yoga node of the widget. Apart from adding yoga node, YogaWidget adds support for specifying those yoga properties via Qt's stylesheet. (This is done by using Q_PROPERTY). To make this work we need to use something called as Q_OBJECT inside the class which is a C++ macro. Q_OBJECT will be expanded to relevant code by the compiler. In Qt whenever we add Q_OBJECT to a header file, we need to use a pre compiler called Qt MOC (Meta Object Compiler). The way we use it is
|
||||
|
||||
```
|
||||
moc headername.h -o headername_moc.h
|
||||
moc headername.h -o headername_moc.cpp
|
||||
```
|
||||
|
||||
This will run moc on `headername.h` and generate `headername_moc.h`. We will include this file instead of `headername.h`. This is the reason we have `nlabel_moc.h`. If you dont do this. Then it will give a symbol not found error.
|
||||
This will run moc on `headername.h` and generate `headername_moc.cpp`. We will include this file instead of `headername.h`. This is the reason we have `nlabel_moc.cpp`. If you dont do this. Then it will give a symbol not found error.
|
||||
|
||||
I hope QLabel's example is enough for now. For more examples and inspirations we can take a look at other wrapped widgets.
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{
|
||||
"includes": [
|
||||
"./config/application.gypi",
|
||||
"./config/moc.gypi",
|
||||
'./config/yoga.gypi'
|
||||
],
|
||||
"targets": []
|
||||
|
||||
@ -16,12 +16,10 @@
|
||||
"../src/cpp/core/YogaWidget/yogawidget.cpp",
|
||||
# wrapped cpps
|
||||
"../src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
|
||||
"../src/cpp/QtGui/QWidget/nwidget.cpp",
|
||||
"../src/cpp/QtGui/QWidget/qwidget_wrap.cpp",
|
||||
'../src/cpp/core/FlexLayout/flexnode_wrap.cpp',
|
||||
'../src/cpp/core/FlexLayout/flexlayout_wrap.cpp',
|
||||
"../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp",
|
||||
"../src/cpp/QtWidgets/QLabel/nlabel.cpp",
|
||||
"../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp",
|
||||
"../src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp",
|
||||
"../src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp",
|
||||
|
||||
9
config/moc.gypi
Normal file
9
config/moc.gypi
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"includes": [],
|
||||
"target_defaults": {
|
||||
"sources": [
|
||||
"../src/cpp/QtGui/QWidget/nwidget_moc.cpp",
|
||||
"../src/cpp/QtWidgets/QLabel/nlabel_moc.cpp",
|
||||
],
|
||||
}
|
||||
}
|
||||
@ -16,5 +16,4 @@
|
||||
"../deps/yoga/event/event.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
#include "nwidget_moc.h"
|
||||
@ -1 +0,0 @@
|
||||
#include "nlabel_moc.h"
|
||||
Loading…
Reference in New Issue
Block a user