Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Resource management in a Qt class
manasij7479 last edited by
I have a Widget class that displays certain information from a file.
Say, the information can be shown in a QVBoxLayout which contains a number of QLabels depending on the file.
The class also has a slot which is executed when a new file is opened.
I want everything currently visible to be discarded and display the information from the new file.
How do I 'delete' the old objects?
I can not reuse(QLabel::setText) them, since the number of items will vary.
When I just call delete the delete operator on them, I get a segfault.
What is the recommended way of handling this in Qt?
Xander84 last edited by
it should work if you just remove the root widget of your layout from the view and then invoke the deleteLater() slot maybe?
Also in the last I had no problem with just deleting a widget that was still visible, but that should be bad practice no matter if that works or not :D