[Qt-interest] problem with QMainWindow setCentralWidget andstackedWidget
Meir Yanovich
meiry242 at gmail.com
Sat May 15 07:36:01 CEST 2010
Hi
well i do add layout to the parent page in the stack widget this is my
original setup
but i need the effect im getting from the setCentralWidget that is widget
that is attached to the adge of the main window ,this is the look im looking
for and can't get it via the designer .
here is my set up how can i change it ?
MainWindow->resize(339, 297);
centralwidget = new QWidget(MainWindow);
centralwidget->setMaximumSize(QSize(16777214, 16777215));
verticalLayout = new QVBoxLayout(centralwidget);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
stackedWidget = new QStackedWidget(centralwidget);
stackedWidget->setObjectName(QString::fromUtf8("stackedWidget"));
page = new QWidget();
page->setObjectName(QString::fromUtf8("page"));
verticalLayout_2 = new QVBoxLayout(page);
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
webView = new QWebView(page);
webView->setObjectName(QString::fromUtf8("webView"));
QSizePolicy sizePolicy(QSizePolicy::Preferred,
QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(webView->sizePolicy().hasHeightForWidth());
webView->setSizePolicy(sizePolicy);
webView->setAutoFillBackground(true);
webView->setUrl(QUrl("about:blank"));
verticalLayout_2->addWidget(webView);
stackedWidget->addWidget(page);
page_2 = new QWidget();
page_2->setObjectName(QString::fromUtf8("page_2"));
verticalLayout_3 = new QVBoxLayout(page_2);
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
treeView = new QTreeView(page_2);
treeView->setObjectName(QString::fromUtf8("treeView"));
treeView->setAlternatingRowColors(true);
treeView->setRootIsDecorated(false);
verticalLayout_3->addWidget(treeView);
stackedWidget->addWidget(page_2);
verticalLayout->addWidget(stackedWidget);
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
retranslateUi(MainWindow);
stackedWidget->setCurrentIndex(0);
On Sat, May 15, 2010 at 8:02 AM, Tony Rietwyk <tony.rietwyk at rightsoft.com.au
> wrote:
> 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
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100515/ff9c33ec/attachment.html
More information about the Qt-interest-old
mailing list