summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/addressbook-sdk.qdoc38
-rw-r--r--doc/examples/addressbook-sdk/part2/addressbook.h5
-rw-r--r--doc/examples/addressbook-sdk/part5/finddialog.cpp4
-rw-r--r--doc/examples/addressbook-sdk/part5/finddialog.h8
-rw-r--r--doc/images/addressbook-tutorial-part5-signals-and-slots.pngbin0 -> 5542 bytes
5 files changed, 50 insertions, 5 deletions
diff --git a/doc/addressbook-sdk.qdoc b/doc/addressbook-sdk.qdoc
index 1974c129ed..3194ad70b2 100644
--- a/doc/addressbook-sdk.qdoc
+++ b/doc/addressbook-sdk.qdoc
@@ -315,6 +315,12 @@
\snippet examples/addressbook-sdk/part2/addressbook.h members1
+ The Qt types used for our private members, e.g., QPushButton, QLineEdit,
+ QTextEdit, etc., need to be included with the \c include directive, as
+ shown below:
+
+ \snippet examples/addressbook-sdk/part2/addressbook.h include
+
\note The names, e.g., \c addButton etc., correspond to the name of the
actual object. You can modify them by double-clicking on their names within
\QD's \gui{Object Inspector}.
@@ -727,6 +733,7 @@
dialog that can prompt the user for a contact's name. Qt provides QDialog,
which we subclass in this chapter, to implement a FindDialog class.
+
\section1 Designing \c FindDialog
#image
@@ -743,6 +750,7 @@
in a horizontal layout. Then set a top level layout - either horizontal or
vertical.
+
\section1 Implementing \c FindDialog
Let's look at \c{FindDialog}'s header file. Here, we need to provide
@@ -751,8 +759,38 @@
\snippet examples/addressbook-sdk/part5/finddialog.h private members
+ We define a public function, \c getFindText(), to be used by classes that
+ instantiate \c FindDialog. This function allows the these classes to obtain
+ the search string entered by the user. A public slot, \c findClicked(), is
+ also defined to handle the search string when the user clicks the \gui Find
+ button.
+
+ \snippet examples/addressbook-sdk/part5/finddialog.h getFindText
+ \dots
+ \snippet examples/addressbook-sdk/part5/finddialog.h findClicked
+
+ Now, lets look at our constructor in the \c{finddialog.cpp} file. Here, we
+ set up the private variables, \c lineEdit, \c findButton, and \c findText.
+
+ \snippet examples/addressbook-sdk/part5/finddialog.cpp constructor
+
+ We connect our signals to their respective slots. Notice that
+ \c{findButton}'s \l{QPushButton:}{clicked()} signal is connected to
+ \c findClicked() and \l{QDialog::}{accept()}. The \l{QDialog::}{accept()}
+ slot provided by QDialog hides the dialog and sets the result code to
+ \l{QDialog::}{Accepted}. We use this function to help \c{AddressBook}'s
+ \c findContact() function know when the \c FindDialog object has been
+ closed. We will explain this logic in further detail when discussing the
+ \c findContact() function.
+
+ \image addressbook-tutorial-part5-signals-and-slots.png
+ In \c findClicked(), we validate to ensure that the user did not click the
+ \gui Find button without entering a contact's name. Then, we set
+ \c findText to the search string, extracted from \c lineEdit. After that,
+ we clear the contents of \c lineEdit and hide the dialog.
+ \snippet examples/addressbook-sdk/part5/finddialog.cpp findClicked
*/
diff --git a/doc/examples/addressbook-sdk/part2/addressbook.h b/doc/examples/addressbook-sdk/part2/addressbook.h
index efea5d177b..69486cb8cf 100644
--- a/doc/examples/addressbook-sdk/part2/addressbook.h
+++ b/doc/examples/addressbook-sdk/part2/addressbook.h
@@ -1,13 +1,13 @@
-//! [class definition]
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
+//! [include]
#include <QtGui/QWidget>
#include <QtGui/QPushButton>
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
#include <QtGui/QMessageBox>
-
+//! [include]
namespace Ui
{
@@ -48,4 +48,3 @@ private:
};
#endif // ADDRESSBOOK_H
-//! [class definition]
diff --git a/doc/examples/addressbook-sdk/part5/finddialog.cpp b/doc/examples/addressbook-sdk/part5/finddialog.cpp
index 89ee5e083a..1a464b7090 100644
--- a/doc/examples/addressbook-sdk/part5/finddialog.cpp
+++ b/doc/examples/addressbook-sdk/part5/finddialog.cpp
@@ -1,6 +1,7 @@
#include "finddialog.h"
#include "ui_finddialog.h"
+//! [constructor]
FindDialog::FindDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::FindDialog)
@@ -18,12 +19,14 @@ FindDialog::FindDialog(QWidget *parent) :
setWindowTItle(tr("Find a Contact"));
}
+//! [constructor]
FindDialog::~FindDialog()
{
delete m_ui;
}
+//! [findClicked]
void FindDialog::findClicked()
{
QString text = lineEdit->text();
@@ -38,6 +41,7 @@ void FindDialog::findClicked()
hide();
}
}
+//! [findClicked]
QString FindDialog::getFindText()
{
diff --git a/doc/examples/addressbook-sdk/part5/finddialog.h b/doc/examples/addressbook-sdk/part5/finddialog.h
index 9df1df8998..aef5aee9fa 100644
--- a/doc/examples/addressbook-sdk/part5/finddialog.h
+++ b/doc/examples/addressbook-sdk/part5/finddialog.h
@@ -2,8 +2,8 @@
#define FINDDIALOG_H
#include <QtGui/QDialog>
-#include <QLineEdit>
-#include <QPushButton>
+#include <QtGui/QLineEdit>
+#include <QtGui/QPushButton>
namespace Ui {
class FindDialog;
@@ -14,10 +14,14 @@ class FindDialog : public QDialog {
public:
FindDialog(QWidget *parent = 0);
~FindDialog();
+//! [getFindText]
QString getFindText();
+//! [getFindText]
+//! [findClicked]
public slots:
void findClicked();
+//! [findClicked]
//! [private members]
private:
diff --git a/doc/images/addressbook-tutorial-part5-signals-and-slots.png b/doc/images/addressbook-tutorial-part5-signals-and-slots.png
new file mode 100644
index 0000000000..1771e7bbbf
--- /dev/null
+++ b/doc/images/addressbook-tutorial-part5-signals-and-slots.png
Binary files differ