[Qt-interest] Upcasting to Derived Widget crashes
Srdjan Todorovic
todorovic.s at googlemail.com
Mon Apr 20 17:09:31 CEST 2009
Hi,
2009/4/20 Srdjan Todorovic <todorovic.s at googlemail.com>:
> 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.
Whoops! Ignore that. I should drink more coffee before replying ;)
Although, having said that, I have this suspicion that setupUi() is
instanciating another FolderPane...
Check the header to see if this is indeed happening.
>> //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.
Try using a debugger, it might show you where the crash happens. It
will also let you look at values of your variables, so you can get a
clearer picture of what's happening.
Srdjan
More information about the Qt-interest-old
mailing list