The return from QMdiArea::activeSubWindow() is always a pointer to a QMdiSubWindow. What you are trying to determine is the class of the widget contained inside the QMdiSubWindow. You can do that with qobject_cast:
QMdiSubWindow *sw = mdiArea->activeSubWindow();
if (sw) {
if (FooWidget *foo = qobject_cast<FooWidget*>(sw->widget())) {
// do something FooWidget specific
}
else if (BarWidget *bar = qobject_cast<BarWidget*>(sw->widget())) {
// do something BarWidget specific
}
}
QMdiSubWindow *sw = mdiArea->activeSubWindow();
if (sw) {
if (FooWidget *foo = qobject_cast<FooWidget*>(sw->widget())) {
// do something FooWidget specific
}
else if (BarWidget *bar = qobject_cast<BarWidget*>(sw->widget())) {
// do something BarWidget specific
}
}
To copy to clipboard, switch view to plain text mode
You probably want to do this work in a slot attached to the subWindowActivated() signal.
If you have widgets of the same class but with different purposes then you could use the QObject::name() to differentiate them.
You could just keep a track of the QMdiSubwindow pointers you got when you created the the sub windows and compare those to the active one.
Bookmarks