Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Difficulty: 1/10
Date added: 19th of October 2012
In this exercise I will elaborate on
the answer of exercise 'Qt hide and show #2'.
The following program flow works:
- On startup, the first dialog shows:

- On the first dialog, pressing the button with the text 'Show second', results in hiding the first and showing the second dialog:

- On the second dialog, pressing the button with the text 'Back to first', results in going back to the first dialog
- On the second dialog, pressing the button with the text 'Go to third', results in hiding the second and showing the third dialog:

- On the third dialog, pressing the button with the text 'Back to first', results in going back to the first dialog.
- On the third dialog, pressing the button with the text 'Back to second', results in going back to the second dialog.
The solution given at the answer of exercise 'Qt hide and show #2' works, but
there is still the need to add the needed signals and slots to every child and parent window.
Question
Refactor the code, by adding a new class called QtHideAndShowDialog.
Code
Qt project file: CppExerciseQtHideAndShow3.pro
QT += core gui
TARGET = CppExerciseQtHideAndShow3
TEMPLATE = app
SOURCES += \
main.cpp\
firstdialog.cpp \
seconddialog.cpp \
thirddialog.cpp
HEADERS += \
firstdialog.h \
seconddialog.h \
thirddialog.h
FORMS += \
firstdialog.ui \
seconddialog.ui \
thirddialog.ui
|
firstdialog.h
firstdialog.cpp
main.cpp
seconddialog.h
seconddialog.cpp
thirddialog.h
thirddialog.cpp
#include "thirddialog.h"
#include "ui_thirddialog.h"
ThirdDialog::ThirdDialog(QWidget *parent) :
QDialog(parent),
m_back_to_which_dialog(2), //When user closes the dialog, go back to the previous/second dialog
ui(new Ui::ThirdDialog)
{
ui->setupUi(this);
}
ThirdDialog::~ThirdDialog()
{
delete ui;
}
void ThirdDialog::closeEvent(QCloseEvent *)
{
emit close_me();
}
void ThirdDialog::on_button_back_to_first_clicked()
{
m_back_to_which_dialog = 1;
close();
}
void ThirdDialog::on_button_back_to_second_clicked()
{
m_back_to_which_dialog = 2;
close();
}
|
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.

This page has been created by the tool CodeToHtml