|
5 | 5 | #include <QLabel> |
6 | 6 | #include <QDebug> |
7 | 7 |
|
8 | | -HelloQt::HelloQt( QWidget* parent ) |
9 | | -:QWidget( parent ) |
10 | | -{ |
11 | | -// The memory management is not done explicitly but by using the parent relationship built into Qt |
12 | | -// The tr calls are not strictly neccesary, but it is all that is needed for future i18n. |
13 | | -auto mainLayout = new QVBoxLayout; |
14 | | -auto descriptiveLabel = new QLabel( tr("Descriptive") ); |
15 | | -auto pushButton = new QPushButton( tr("Push me!") ); |
16 | | -auto grouping = new QHBoxLayout; |
17 | | -auto directButton = new QPushButton( tr( "Directly!" ) ); |
18 | | -auto fatal = new QPushButton( tr( "Don't push this button" ) ); |
19 | | -// By adding the widgets to the main widget, they get parented and the parenting takes care of freeing the memory |
20 | | -grouping->addWidget( descriptiveLabel ); |
21 | | -grouping->addWidget( pushButton ); |
22 | | -mainLayout->addLayout( grouping ); |
23 | | -mainLayout->addWidget( directButton ); |
24 | | -mainLayout->addWidget( fatal ); |
25 | | -setLayout( mainLayout ); |
26 | | -// Signals and slots are use to simply define relationships between actions and effects |
27 | | -// By using this "new style" connect the types are checked at compile time to match |
28 | | -connect( pushButton, &QPushButton::clicked, this, &HelloQt::writeToDebug ); |
29 | | -// Lambdas can also be used as can ordinary freestanding functions |
30 | | -connect( directButton, &QPushButton::clicked, [](){ qDebug() << tr( "I am in line" ); } ); |
31 | | -// Most usefull signals and slots are already built into the framework. |
32 | | -connect( fatal, &QPushButton::clicked, this, &HelloQt::close ); |
| 8 | +HelloQt::HelloQt(QWidget *parent) : QWidget(parent) { |
| 9 | + // The memory management is not done explicitly but by using the parent |
| 10 | + // relationship built into Qt |
| 11 | + // The tr calls are not strictly neccesary, but it is all that is needed for |
| 12 | + // future i18n. |
| 13 | + auto mainLayout = new QVBoxLayout; |
| 14 | + auto descriptiveLabel = new QLabel(tr("Descriptive")); |
| 15 | + auto pushButton = new QPushButton(tr("Push me!")); |
| 16 | + auto grouping = new QHBoxLayout; |
| 17 | + auto directButton = new QPushButton(tr("Directly!")); |
| 18 | + auto fatal = new QPushButton(tr("Don't push this button")); |
| 19 | + // By adding the widgets to the main widget, they get parented and the |
| 20 | + // parenting takes care of freeing the memory. |
| 21 | + // Laying out in layouts makes the GUI automatically resize. |
| 22 | + grouping->addWidget(descriptiveLabel); |
| 23 | + grouping->addWidget(pushButton); |
| 24 | + mainLayout->addLayout(grouping); |
| 25 | + mainLayout->addWidget(directButton); |
| 26 | + mainLayout->addWidget(fatal); |
| 27 | + setLayout(mainLayout); |
| 28 | + // Signals and slots are use to simply define relationships between actions |
| 29 | + // and effects |
| 30 | + // By using this "new style" connect the types are checked at compile time to |
| 31 | + // match |
| 32 | + connect(pushButton, &QPushButton::clicked, this, &HelloQt::writeToDebug); |
| 33 | + // Lambdas can also be used as can ordinary freestanding functions |
| 34 | + connect(directButton, &QPushButton::clicked, |
| 35 | + []() { qDebug() << tr("I am in line"); }); |
| 36 | + // Most usefull signals and slots are already built into the framework. |
| 37 | + connect(fatal, &QPushButton::clicked, this, &HelloQt::close); // could just use close |
33 | 38 | }; |
34 | 39 |
|
35 | | -HelloQt::~HelloQt() |
36 | | -{ |
37 | | -// Nothing to do here, the parent system makes sure that all the elements that are |
38 | | -// parented to this is cleaned up |
| 40 | +HelloQt::~HelloQt() { |
| 41 | + // Nothing to do here, the parent system makes sure that all the elements that |
| 42 | + // are parented to this is cleaned up |
39 | 43 | } |
40 | 44 |
|
41 | | -void HelloQt::writeToDebug( void ) |
42 | | -{ |
43 | | -qDebug() << tr( "I don't know what I was supposed to debug here..." ); |
| 45 | +void HelloQt::writeToDebug(void) { |
| 46 | + qDebug() << tr("I don't know what I was supposed to debug here..."); |
44 | 47 | } |
45 | | - |
|
0 commit comments