Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Difficulty: 2/10
Date added: 14th of October 2012
In this exercise I will show an error I have wrestled with for some weeks, with the goal to prevent you having the same trouble. I will assume some basic Qt knowledge.
I desired to have the following program flow:
I want to hide a dialog when showing another. This prevent the user from needlessly seeing the older dialog.
Also note that the program returns an exit code of zero, which denotes that the program ended without an error.
The code shown below, however, has an incorrect flow: from the third dialog, the user is always taken back to the first dialog. Why?
It is checked that the if statement in SecondDialog really takes the correct branch.
If the if-statement in SecondDialog is replaced by 'this->show()', the incorrect behavior persists.
The solution can really be found in the code shown.
Note that the -from my point of- unexpected behavior is actually the expected behavior, according to this bug report.
QT += core gui |
#ifndef FIRSTDIALOG_H |
#include "seconddialog.h" |
#include <QtGui/QApplication> |
#ifndef SECONDDIALOG_H |
#include <cassert> |
#ifndef THIRDDIALOG_H |
#include "thirddialog.h" |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
This page has been created by the tool CodeToHtml