So i have a program that uses a subclass of QMainWindow for QMdiArea widgets. I’m only doing this because QDockWidgets can only be used in a QMainWindow (and my subclass needed dock widgets).
I was testing my class’s serialization for saving purposes and my pointer wasn’t correct. Here is the code
if (ui->mdiMain->subWindowList().length() > 0)
{
QString path = QFileDialog::getSaveFileName(this, "Save Build Order", "" ,"*.cbo");
if (path > 0)
{
QFile file(path, this);
if (file.open(QFile::WriteOnly) == true)
{
QWidget* widget = reinterpret_cast<QWidget*>(ui->mdiMain->activeSubWindow());
WidgetBuildOrder* widgetBuildOrder = reinterpret_cast<WidgetBuildOrder*>(widget);
QDataStream stream(&file);
stream << widgetBuildOrder;
file.close();
ui->statusBar->showMessage("Save Successful.", 5000);
}
}
}
}
WidgetBuildOrder is a subclass of MainWindow.
so my thought was that I could keep casting the pointer to what it actually is. When I created the MDI area, i passed a new WidgetBuildOrder. Is there a way to do this?
To Clarify, after the casting I do get a pointer its just pointing to garbage. Not the values set in the WidgetBuildOrder I actually have open.
Any help will be appreciated,
Thanks,
Jec
QMdiArea::activeSubWindowreturns aQMdiSubWindow*, or 0 it theQMdiAreadoesn’t have the focus.As you can’t possibly have a class that inherits from
QMainWindowandQMdiSubWindow, what you want is to get the widget inside the current sub-window: