1

I am building an application, which will be creating/deleting QMainWindow(along with a lot of QWidgets), on user input. One thing, which surprised me, is that the CPU usage keeps on increasing while the operation is going on.And It never comes down to a lower value, even after the operation has been stopped..

All the other GUI related things dont present a problem.Aforesaid thing happens only when I am creating/deleting QWidgets.

while creating

QWidgets *widget = new QWidget(parent);

& to delete it

widget->hide();
delete widget;

e.g. I am creating them using new and deleting those widgets using delete.In fact memory usage is also increasing.I suspect that the widgets are not being deleted; they are getting attached to root window. That is why CPU utilization is increasing.

What is the problem in this regard

manmatha.roy
  • 577
  • 1
  • 9
  • 22
  • Some code related to your issue will help. – Metoo Jan 30 '14 at 12:07
  • 1
    Code will be useful, but `new` and `delete` create and release memory, so the CPU consumption could be something else running wild. – Nicholas Smith Jan 30 '14 at 12:15
  • Try replacing delete with deleteLater, which will just place a delete request in the q. This may even out CPU usage a little bit? – m. c. Jan 30 '14 at 18:46
  • @Metoo:to produce the full code is not possible.Hence only relevant portion I have given.See the edit – manmatha.roy Jan 31 '14 at 06:11
  • @user081289 Nothing looks suspicious with above piece of code and i think it would be good if you can go thru : http://qt-project.org/doc/qt-4.8/qt-performance.html .Since if i am not wrong you are developing on a embedded platform – Metoo Jan 31 '14 at 06:28
  • @user081289 In Qt there is always a parent-child relation between widgets. When the parent widget is destroyed, it will delete all its children. Usually, you do not need to think about explicitly deleting any widgets but the top level widgets, i.e., windows and dialogs. Qt will take care of the deleting any child widgets. – Metoo Jan 31 '14 at 06:41

0 Answers0