[Qt-interest] QWizardPage::wizard() overprotected?
Niels Dekker - no return address
noreply at this.is.invalid
Thu Dec 11 10:50:27 CET 2008
Scott Aron Bloom wrote:
> Since your deriving from WizardPage anyway.. why not just overload
> wizard() and make it public?
Thanks for your reply. So you say I'd have to override wizard() on all of my
derived WizardPage classes, to make it public. But then why wasn't it public
in the first place? I mean, what does Qt protect me against?
> That said, why do you need access to the wizard outside of the
> WizardPage?
>From within any of my pages, I need to find my way back to the status bar of
my wizard. Unfortunately, a QWizard cannot have a status bar, so I had to put
it onto a QMainWindow. Anyway, to avoid code duplication, I wrote a single
function to get the status bar belonging to my wizard:
// Returns the status bar, specific to my application.
QStatusBar& getStatusBar(const QWizardPage& page)
{
// Get the "protected" wizard from the page.
const QWizard* const wizard = getWizard(page);
assert(wizard != NULL);
// My wizard has a QMainWindow as parent.
const QMainWindow* const mainWindow =
dynamic_cast<const QMainWindow *>(wizard->parent());
assert(mainWindow != NULL);
QStatusBar* statusBar = mainWindow->statusBar();
assert(statusBar != NULL);
return *statusBar;
}
Now I can directly get the status bar, from within any of my pages:
getStatusBar(*this).showMessage(tr("Status okay!"));
Doesn't that sound reasonable to you?
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
More information about the Qt-interest-old
mailing list