[Qt-interest] Is it safely to use delete to remove a QWidget from the display?

yi xia max.xiayi at gmail.com
Mon Sep 14 09:35:07 CEST 2009


Hi All,

I am using a qtopia-free-2.2.0 , and use multithread version.

The framework of my applications

QMainWindow *_rootWin
               |
               |
QWidgete* Screen1, Screen2, Screen3 ...


*Screen1 , Screen2 , Screen3 is created in a thread, everytime a new Screen
is created , I call the following lines to hide the current screen.*

newscreen->show();
 /* hide the last content window */
 int nwin = _rootwin->children()->count();
 if (nwin > _nInitialWins + 1 )  //_nInitialWins is the screen count before
I create _rootWin, on PC(QT-3.3.8) , it is 7, on my board it is
2(qtopia-2.2.0)
 {
  QObjectList *childrens = (QObjectList *)_rootwin->children();
  QWidget *lastWin = (QWidget *)(childrens->at(nwin - 2));
  if (lastWin)
   lastWin->hide();
 }

*everytime a Screen I need it to be disappeared and show the
last-before-this screen, I call the following lines*

 delete current_screen;
 int nwin = _rootwin->children()->count();
 if(nwin > 0)
 {
  QObjectList *childrens = (QObjectList *)_rootwin->children();
  QWidget *lastWin = (QWidget *)(childrens->at(nwin - 1));
  if (lastWin)
  {
   lastWin->show();
   nwin = lastWin->children()->count();
   if(nwin > 0)
   {
    QObjectList *subchildrens = (QObjectList *)lastWin->children();
    QWidget *sublastWin = (QWidget *)(subchildrens->at(nwin - 1));
    sublastWin->setFocus();
   }
  }
 }


*This framework works fine under PC, my PC is QT-3.3.8-X11,*
*however , when this application is ported into ARM board, I get a big
trouble, the problem I have found, but I don't know why,*

The problem on arm board is because after delete a QWidget, the parent's
childrens (QObjectList ) can not save correctly its child's this pointer,
the value it stored will change, for example, if before delete
currentscreen, I print all the pointers by the following lines

int nwin = _rootwin->children()->count();
for(int i = 0; i < nwin; i++)
{
 QObjectList *childrenss = (QObjectList *)_rootwin->children();
 QWidget *lastWinn = (QWidget *)(childrenss->at(i));
 TRACE("%i child this pointer = %x", i, lastWinn);
}

the print out is :
0 child this pointer = 0x3fbbb
1 child this pointer = 0x3fggg
2 child this pointer = 0x3feee
3 child this pointer = 0x3fffff

then after delete current screen, using the last printout method, I
assume  it should be
 0 child this pointer = 0x3fbbb
1 child this pointer = 0x3fggg
2 child this pointer = 0x3feee

On PC(qt-3.3.8-x11) , it always behave like I expected, but On Arm
board(QTOPIA-2.2.0), it is not the case, I feel very disappointed about
this,

Can anyboday tell me why? and is it safe to use multithread qt and use
delete like this way?

Regards

Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090914/42b96925/attachment.html 


More information about the Qt-interest-old mailing list