[Qt-interest] problem with QMainWindow setCentralWidget andstackedWidget

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Sat May 15 07:02:32 CEST 2010


Meir, 
 
This is basic C++ pointer problem.  Your debugging should have shown: 
 
- that the ui.stacked_widget object is invalid when you called
setCurrentIndex, 
- since the pointer has not changed, but the memory it points to has, 
- you need to check whether the stacked widget has been deleted, 
- you add a breakpoint to its destructor, 
- and find that it occurs during setCentralWidget, or shortly afterwards in
a delete object event. 
 
setCentralWidget(ui.webView) is reparenting the webView and deleting the
stacked widget, so you get a dangling reference to it in your ui object.
Hence it crashes next time you use it with setCurrentIndex.  
 
* if the pointer had changed, that would imply the ui object had been
trashed, so its enclosing object has been deleted (or overwritten).  
 
To center the webView try adding a layout to it's parent page in the stacked
widget and leave the stacked widget as the central object.  
 
Tony.
 

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Meir Yanovich
Sent: Saturday, 15 May 2010 14:07
To: qt-interest at trolltech.com
Subject: [Qt-interest] problem with QMainWindow setCentralWidget
andstackedWidget


Hello 
i have gui the i created in the designer , simple one .
QMainWIndow that contains stackedWidget , the application starts with 
stackedWidget index 0 that contains qwebkit widget and after some user flow
,it changes to stackedWidget
index 1 that contains QTree widget , to center the first widget i use in the
QMainWindow constractor this line of code
this->setCentralWidget(ui.webView); but when the application switching to
index number 1 im getting exception that is 
coming from the switching command . 
why ?



No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.819 / Virus Database: 271.1.1/2873 - Release Date: 05/15/10
04:26:00




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100515/3e5f65c9/attachment.html 


More information about the Qt-interest-old mailing list