I know this problem has been already discussed, and I know it has to do with the fact that deleteLater() only is effective after passing again control to the main loop.
Here there is my simple code:
squares = MainWindow.findChildren(QtWidgets.QFrame,"squaresFrame")
print(f"{len(squares)} before delete") #they are 10
for square in squares:
square.deleteLater()
squares = MainWindow.findChildren(QtWidgets.QFrame,"squaresFrame")
print(f"{len(squares)} after delete") #they are still 10
The two prints always print the same number, in my case 10, meaning that the squares are still around.
Is there a way to delete the squares immediately?
For example how can I pass control to the main loop and take it back to my script without user interaction?