|
|
On 06.07.06 14:23:55, denebet wrote:
> if ( m_Layout ) {
> if ( m_TopWidget ) {
> m_Layout->removeWidget(m_TopWidget );
> m_TopWidget->setParent( 0 ); // <-- added to avoid the sigfault
> }
>
> delete m_Layout;
> m_Layout=0;
> }
> if ( m_ScrollBg ) {
> //delete all the widgets
> delete m_ScrollBg;
> m_ScrollBg=0;
> }
> m_ScrollBg=new QWidget(0 );
> m_Layout=new QVBoxLayout( m_ScrollBg );
>
> if ( !m_TopWidget ) {
> m_TopWidget =buildTopWidget();
> }
> m_Layout->addWidget(m_TopWidget ); // <-sigfault here
> //m_TopWidget->show(); if the above line is commented
> // and this one commented out m_TopWidget shows without problem
>
> I am just an hobbyist so I am conscious that they are probably better ways
> than that but what puzzles me is why m_TopWidget was not destroyed when
> m_ScrollBg is deleted and m_TopWidget's parent not set to 0.
Aah, actually the topWidget is deleted, but the variable is still
pointing to a memory address. So the if (!m_TopWidget) evaluates to
false, because m_TopWidget is not reset to 0. Then when you try to add
the top widget to the layout, the code tries to access member functions
of the widget, but as the variable points to invalid memory you get a
segfault.
So when you delete m_ScrollBg, you should not only set that variable to
0, but all other variables that are childs under m_ScrollBg in the
object tree. Then you can remove the m_TopWidget->setParent(0);
Andreas
--
You will live to see your grandchildren.
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|