I've wrote a generic method which should create mdi children. the central widgets of the created mdi children have different classes and I think it does not work as expected because everything is "casted down to QWidget*"
it does not work as expected in that the mdi child is created, but the central widget is empty (it does not have the controls I'd expect it to have)
Here's the code I consider relevant
//------------------------------------------
#include "SubWindowObjects.h"
#include "utils.h"
dbg();
this->subWindow = new QMdiSubWindow(widget);
this->switchAction = bar->addWidget(this->switchButton);
this->switchAction->setVisible(false);
this->mdiArea = mdiArea;
this->mdiArea->addSubWindow(this->subWindow);
this->subWindow->hide();
}
SubWindowObjects::~SubWindowObjects() {
//TODO delete objects
}
void SubWindowObjects::show() {
this->switchAction->setVisible(true);
this->subWindow->show();
}
void SubWindowObjects::hide() {
this->switchAction->setVisible(false);
this->subWindow->hide();
}
//------------------------------------------
SoftpediaClient
::SoftpediaClient(QWidget *parent
){
ui.setupUi(this);
this->mdiArea = new QMdiArea(this);
setCentralWidget(this->mdiArea);
this
->switchBar
= new QToolBar(tr
("Switch Bar"));
this->switchBar->setMinimumWidth(100);
addToolBar(Qt::LeftToolBarArea,this->switchBar);
dbg();
this
->subwindows
["login"] = new SubWindowObjects
(this
->switchBar,
new LoginDialog
(this
->mdiArea
),
new QString("Login"),this
->mdiArea
);
dbg();
this->subwindows["login"]->hide();
dbg("init");
}
//------------------------------------------
LoginDialog
::LoginDialog(QWidget *parent
){
ui.setupUi(this);
}
//------------------------------------------
#include "SubWindowObjects.h"
#include "utils.h"
SubWindowObjects::SubWindowObjects(QToolBar* bar, QWidget* widget,QString *title, QMdiArea* mdiArea) {
dbg();
this->subWindow = new QMdiSubWindow(widget);
this->switchButton = new QPushButton(*title);
this->switchAction = bar->addWidget(this->switchButton);
this->switchAction->setVisible(false);
this->mdiArea = mdiArea;
this->mdiArea->addSubWindow(this->subWindow);
this->subWindow->hide();
}
SubWindowObjects::~SubWindowObjects() {
//TODO delete objects
}
void SubWindowObjects::show() {
this->switchAction->setVisible(true);
this->subWindow->show();
}
void SubWindowObjects::hide() {
this->switchAction->setVisible(false);
this->subWindow->hide();
}
//------------------------------------------
SoftpediaClient::SoftpediaClient(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
this->mdiArea = new QMdiArea(this);
setCentralWidget(this->mdiArea);
this->switchBar = new QToolBar(tr("Switch Bar"));
this->switchBar->setMinimumWidth(100);
addToolBar(Qt::LeftToolBarArea,this->switchBar);
dbg();
this->subwindows["login"] = new SubWindowObjects(this->switchBar,new LoginDialog(this->mdiArea),new QString("Login"),this->mdiArea);
dbg();
this->subwindows["login"]->hide();
dbg("init");
}
//------------------------------------------
LoginDialog::LoginDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
To copy to clipboard, switch view to plain text mode
SubWindowObjects aggregates gui elements which are related to each other (ie the button on a tool bar, the action bound to it, the mdi child, and maybe more to come)
on line 5, QWidget* widget will be the central widget of the mdi child, but I'm obviously missing something 
maybe I'm doing it wrong on line 39, but the object should not be wiped out from the heap, ie: new LoginDialog(this->mdiArea)
I've attached the complete project.
Bookmarks