Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

You need to iterate through all widgets and remove each of them:

for(int i = stackedWidget->count(); i >= 0; i--)
    QWidget* widget = stackedWidget->widget(i);
    stackedWidget->removeWidget(widget);
    widget->deleteLater();
                I'm not sure this will work... better do a while(stackedWidget->count() > 0){ QWidget* widget = stackedWidget->widget(0); /*....*/ }
– Mr. Developerdude
                Nov 4, 2017 at 1:07

I tried this example in Python As a result of 5 pages, only 3 were deleted.

I did some checks and as result come up with an understanding, in a loop page with index 0 needs to be deleted all the time, because then you delete page 0, page 1 becomes 0

pages = self.ui.stackedWidget_2.count() for i in range(pages): widget = self.ui.stackedWidget_2.widget(0); self.ui.stackedWidget_2.removeWidget(widget);

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.