Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Answer of exercise: Qt hide and show #3 is the answer of
the exercise Qt hide and show #3.
Solution
Qt project file: CppExerciseQtHideAndShow3Answer.pro
QT += core gui
TARGET = CppExerciseQtHideAndShow3Answer
TEMPLATE = app
SOURCES += \
main.cpp\
firstdialog.cpp \
seconddialog.cpp \
thirddialog.cpp \
qthideandshowdialog.cpp
HEADERS += \
firstdialog.h \
seconddialog.h \
thirddialog.h \
qthideandshowdialog.h
FORMS += \
firstdialog.ui \
seconddialog.ui \
thirddialog.ui
|
firstdialog.h
firstdialog.cpp
#include "seconddialog.h"
#include "firstdialog.h"
#include "ui_firstdialog.h"
FirstDialog::FirstDialog(QWidget *parent) :
QtHideAndShowDialog(parent),
ui(new Ui::FirstDialog)
{
ui->setupUi(this);
}
FirstDialog::~FirstDialog()
{
delete ui;
}
void FirstDialog::on_pushButton_clicked()
{
SecondDialog d;
this->ShowChild(&d);
}
|
main.cpp
qthideandshowdialog.h
qthideandshowdialog.cpp
seconddialog.h
seconddialog.cpp
#include <cassert>
#include "seconddialog.h"
#include "ui_seconddialog.h"
#include "thirddialog.h"
SecondDialog::SecondDialog(QWidget *parent) :
QtHideAndShowDialog(parent),
ui(new Ui::SecondDialog)
{
ui->setupUi(this);
}
SecondDialog::~SecondDialog()
{
delete ui;
}
void SecondDialog::on_button_back_to_first_clicked()
{
close();
}
void SecondDialog::on_button_goto_third_clicked()
{
ThirdDialog d;
this->ShowChild(&d);
if (d.m_back_to_which_dialog == 1)
{
this->close();
}
}
|
thirddialog.h
thirddialog.cpp
#include "thirddialog.h"
#include "ui_thirddialog.h"
ThirdDialog::ThirdDialog(QWidget *parent) :
QtHideAndShowDialog(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::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