<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Solved] questions about an example of &quot;C++ GUI Programming with Qt 4 (2nd Edition)&quot;]]></title><description><![CDATA[<p dir="auto">There is an example in chapter 2 of the book<br />
finddialog.h<br />
@#ifndef FINDDIALOG_H<br />
#define FINDDIALOG_H</p>
<p dir="auto">#include &lt;QDialog&gt;</p>
<p dir="auto">class QCheckBox;<br />
class QLabel;<br />
class QLineEdit;<br />
class QPushButton;</p>
<p dir="auto">class FindDialog : public QDialog<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
FindDialog(QWidget *parent = 0);</p>
<p dir="auto">signals:<br />
void findNext(const QString &amp;str, Qt::CaseSensitivity cs);<br />
void findPrevious(const QString &amp;str, Qt::CaseSensitivity cs);</p>
<p dir="auto">private slots:<br />
void findClicked();<br />
void enableFindButton(const QString &amp;text);</p>
<p dir="auto">private:<br />
QLabel *label;<br />
QLineEdit *lineEdit;<br />
QCheckBox *caseCheckBox;<br />
QCheckBox *backwardCheckBox;<br />
QPushButton *findButton;<br />
QPushButton *closeButton;<br />
};</p>
<p dir="auto">#endif@<br />
part of finddialog.cpp<br />
@#include &lt;QtGui&gt;</p>
<p dir="auto">#include "finddialog.h"</p>
<p dir="auto">FindDialog::FindDialog(QWidget *parent)//Why is parent never used?<br />
: QDialog(parent)<br />
{<br />
label = new QLabel(tr("Find &amp;what:"));<br />
lineEdit = new QLineEdit;<br />
label-&gt;setBuddy(lineEdit);</p>
<pre><code>caseCheckBox = new QCheckBox(tr("Match &amp;case"));
backwardCheckBox = new QCheckBox(tr("Search &amp;backward"));

findButton = new QPushButton(tr("&amp;Find"));
findButton-&gt;setDefault(true);
findButton-&gt;setEnabled(false);

closeButton = new QPushButton(tr("Close"));

connect(lineEdit, SIGNAL(textChanged(const QString &amp;)),
        this, SLOT(enableFindButton(const QString &amp;)));
connect(findButton, SIGNAL(clicked()),
        this, SLOT(findClicked()));
connect(closeButton, SIGNAL(clicked()),
        this, SLOT(close()));

QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout-&gt;addWidget(label);
topLeftLayout-&gt;addWidget(lineEdit);

QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout-&gt;addLayout(topLeftLayout);
leftLayout-&gt;addWidget(caseCheckBox);
leftLayout-&gt;addWidget(backwardCheckBox);

QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout-&gt;addWidget(findButton);
rightLayout-&gt;addWidget(closeButton);
rightLayout-&gt;addStretch();

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout-&gt;addLayout(leftLayout);
mainLayout-&gt;addLayout(rightLayout);
setLayout(mainLayout);//question:Why isn't it in the way of "object. setLayout(mainLayout); "? And which is object?

setWindowTitle(tr("Find"));//same question
setFixedHeight(sizeHint().height());//same question
</code></pre>
<p dir="auto">}@</p>
]]></description><link>https://forum.qt.io/topic/16300/solved-questions-about-an-example-of-c-gui-programming-with-qt-4-2nd-edition</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 09:04:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/16300.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 29 Apr 2012 15:00:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] questions about an example of &quot;C++ GUI Programming with Qt 4 (2nd Edition)&quot; on Mon, 30 Apr 2012 06:18:45 GMT]]></title><description><![CDATA[<p dir="auto">Thank you,I understand.</p>
]]></description><link>https://forum.qt.io/post/137489</link><guid isPermaLink="true">https://forum.qt.io/post/137489</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 30 Apr 2012 06:18:45 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] questions about an example of &quot;C++ GUI Programming with Qt 4 (2nd Edition)&quot; on Sun, 29 Apr 2012 16:07:09 GMT]]></title><description><![CDATA[<p dir="auto">@<br />
setLayout(mainLayout);//question:Why isn't it in the way of "object. setLayout(mainLayout); "? And which is object?</p>
<pre><code>setWindowTitle(tr("Find"));//same question
setFixedHeight(sizeHint().height());//same question
</code></pre>
<p dir="auto">@<br />
You're applying layout/title/height to object itself in constructor. This is the same as:<br />
@<br />
this-&gt;setLayout(mainLayout);<br />
this-&gt;setWindowTitle(tr("Find"));<br />
this-&gt;setFixedHeight(sizeHint().height());<br />
@<br />
You should read some C++ book of  C++ FAQ about "this".</p>
<p dir="auto">@<br />
FindDialog::FindDialog(QWidget *parent)//Why is parent never used?<br />
@<br />
Technically it is used in init list<br />
@<br />
: QDialog(parent)<br />
@<br />
There is not alway necessary to use parent pointer, as you can see in .h file it is 0 by default. Book that you're reading explains QObject parentship pretty well.</p>
]]></description><link>https://forum.qt.io/post/137421</link><guid isPermaLink="true">https://forum.qt.io/post/137421</guid><dc:creator><![CDATA[gmaro]]></dc:creator><pubDate>Sun, 29 Apr 2012 16:07:09 GMT</pubDate></item></channel></rss>