How to delete a widget from a stacked widget in Qt

Using QStackedWidget to switch between the views, I will be able to traverse between the views.

I am facing problem in some scenarios, where I do not require the widgets, but I want to remove them completely.

QStackedWidget provides the functionality to remove widgets, still the ownership of the widget will be there, I mean widget will be hidden.

I don't want this to be happen - when I call remove widget it should be deleted. How should I handle this?

Answers


Have you tried simply deleting the object after removing it? i.e.

stackWidget->removeWidget(myWidget);
delete myWidget;

Many Qt objects will get automatically removed when deleted. (At least, in the QtGraphics API things work that way) I suspect that simply deleting the object will also remove it, since Qt Objects do emit a signal that they have been deleted.


Need Your Help

Sending image by email, Android?

android image email bitmap

I'm trying to make an application to capture an image and send it by email, I successfully made it by the following code

How can I know if user has opened Notification List?

android notifications

I am working in an application implementing an AccesibilityService, to detect when other applications are sending notifications. That is easy to do extending AccesibilityService class.