Skip to content

Commit feef6c1

Browse files
committed
reduced no of files by optimising moc generation
1 parent 0d10ad8 commit feef6c1

File tree

9 files changed

+13
-8
lines changed

9 files changed

+13
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Taking the example of QLabel, if you look inside the directory `src/cpp/QtWidget
187187
├── QLabel
188188
│   ├── nlabel.cpp
189189
│   ├── nlabel.h <---- Extended QLabel
190-
│   ├── nlabel_moc.h <--- Autogenerated file by qt moc.
190+
│   ├── nlabel_moc.cpp <--- Autogenerated file by qt moc.
191191
│   ├── qlabel_wrap.cpp
192192
│   └── qlabel_wrap.h <--- Wrapper file
193193
```
@@ -201,10 +201,10 @@ The idea is :
201201
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
202202

203203
```
204-
moc headername.h -o headername_moc.h
204+
moc headername.h -o headername_moc.cpp
205205
```
206206

207-
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.
207+
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.
208208

209209
I hope QLabel's example is enough for now. For more examples and inspirations we can take a look at other wrapped widgets.
210210

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"includes": [
33
"./config/application.gypi",
4+
"./config/moc.gypi",
45
'./config/yoga.gypi'
56
],
67
"targets": []

config/application.gypi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
"../src/cpp/core/YogaWidget/yogawidget.cpp",
1717
# wrapped cpps
1818
"../src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
19-
"../src/cpp/QtGui/QWidget/nwidget.cpp",
2019
"../src/cpp/QtGui/QWidget/qwidget_wrap.cpp",
2120
'../src/cpp/core/FlexLayout/flexnode_wrap.cpp',
2221
'../src/cpp/core/FlexLayout/flexlayout_wrap.cpp',
2322
"../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp",
24-
"../src/cpp/QtWidgets/QLabel/nlabel.cpp",
2523
"../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp",
2624
"../src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp",
2725
"../src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp",

config/moc.gypi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"includes": [],
3+
"target_defaults": {
4+
"sources": [
5+
"../src/cpp/QtGui/QWidget/nwidget_moc.cpp",
6+
"../src/cpp/QtWidgets/QLabel/nlabel_moc.cpp",
7+
],
8+
}
9+
}

config/yoga.gypi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
"../deps/yoga/event/event.cpp",
1717
],
1818
}
19-
2019
}

src/cpp/QtGui/QWidget/nwidget.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/cpp/QtWidgets/QLabel/nlabel.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)