[Qt-interest] Upcasting to Derived Widget crashes
Srdjan Todorovic
todorovic.s at googlemail.com
Mon Apr 20 16:47:50 CEST 2009
Hi,
2009/4/20 Neel Basu <neel.basu.z at gmail.com>:
> I've designed a QDockWidget Ui and made a QDockWidget Derived Class that wraps
> that ui.
> and while designing the main window in designer I make its a QDockWidget and
> latter in the Constructor I again assign a new DerivedQDockWidget to it.
>
> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new
> Ui::MainWindowClass){
> //delete ui->folderDock;
> ui->folderDock = new FolderPane(this);
If you look at the uic generated header file, you should notice that
these pointers are not valid until you call setupUi().
ui->folderDock should currently be an invalid pointer.
> //delete ui->mailWidget;
> ui->mailWidget = new MailListWidget(this);
> ui->setupUi(this);
ui->folderDock should now be a valid pointer.
> }
>
> But the above crashes.
> then I added corresponding delete s but it is still crashing
If it keeps crashing, then use a debugger.
> actual type of ui->folderDock is QDockWidget* and FolderPane inherits
> QDockWidget
Hope that helps,
Srdjan
More information about the Qt-interest-old
mailing list