PDA

View Full Version : QMdiArea- closing the Previous subWindow when opening new subWindow is crasing.....



arunpk
15th October 2012, 08:51
Hi all,
I am workin on a designer application which i have created by using Qt Mdi app model... When i am creating a new page(work space) and adding it to the MDI area. As a normal MDI app all the sub Windows will be shown at a time in the MDI Area. But i need to show only one subWindow at a time... Whnever i am opening a new page it should close the previous page and open the new one... when i was trying to use this my app get crashed..

void CWindowController :: createWorkspace()
{
Qt::WindowFlags flags;
flags = Qt::Window | Qt::WindowMinimizeButtonHint;
static int pageNumber = 0;
pageNumber++;

newPage = CWidgetFactory::getInstance()->createPage();
newPage->setSize(800,480);
newPage->setAutoFillBackground(true);
QString name = QString("Page_%1").arg(pageNumber);
newPage->setWidgetName(name);
newPage->setWindowTitle(name);

if(mdiArea->activeSubWindow())
{
mdiArea->activeSubWindow()->close();
}
QMdiSubWindow* subWindow = mdiArea->addSubWindow(newPage,flags);
subWindow->resize(newPage->size());
newPage->show();
}

This is the sample code for creating work space.... Is there any other way to implement this... And in my designer i ll be having one project viewer too which will show all the page names in tree view... when i click on a page name, i need to close the current page on the work space and load this new page on to the work space.. any IDEA!!! :)

dennis81
15th October 2012, 09:33
In which line does it crash exactly?

arunpk
15th October 2012, 09:48
After creating these newPages in the createWorkspace method i ll be adding these page objects to QList<Page*>. When i am trying to access this page names using getWidgetName() which returns the name of the page it crashes, i am geting an "Unavailable synchronous data" value on that page instance...This shows while debugging....

arunpk
15th October 2012, 13:05
I have fixed that crash... Whenever i am creating a new page and placing as an MDI child its width & height will be always minimum even though i am giving the size for that page... I have made modification i the above code... I llnot be using QMdiSubWindow to add the page, instead i ll be directly giving like this..
mdiArea->addSubWindow(newPage,flags);
newPage->resize(800, 480);
newPage->show(); I have tried calling methods like update(), updateGeometry(), repaint(), but cause nothing it still shows the page with minimum size..I have tried so many workaround but nothing helped... Any suggestion regarding this.....
How can add a new widget to the QMdiArea without using an QMdiSubWindow class instance?

dennis81
15th October 2012, 14:00
I use always showMaximized(); for the inner widget.