[SOLVED]QScrollArea deleting issue
-
Hello!
Basically I am using a QScrollArea for a list of labels that change when user presses a button. Now I need to delete all the items in the QScrollArea::widget() before I set a new Widget for the scrollarea... Problem is when I close the area (when I return to the main application widget to be more precise) I want to delete the scrollarea. Tried with delete scrollArea; and with qDeleteAll(scrollArea->children()), and then deleting the scrollArea. In both cases my program crashes. I think this is because of my mistake of having the creation of the scrollArea inside of the widget class for which I want the scrollArea. If this is indeed the case, how can I set my widget from outside of the class? I tried the obvious way but that got me nowhere because my widget Class has a wait period before adding the layout, and after you set the widget to the scroll area you cannot modify the layout anymore. Any ideas?
Thank you in advance.
Qt 4.8.4 MSVC2008 -
I managed to set the widget from outside the class but I still have troubles when trying to delete it... It still crashes my program. Is this a problem caused by deleting the children of the area instead of the children of the widget? Also when setting a new widget the previous widget should be deleted (as stated in the documentation) however this approach crashes my program too... I'm stumped.
-
I've finally managed to solve it... In case anyone else encounters this problem... Just be sure to setAttribute(Qt::WA_DeleteOnClose) for each widget you intend to use in the scrollarea and when you need to close the area and create a new one just use the close() method...