How to stop a method while it uses QWait()
-
Hi,
I have a program that visualizes some sorting algorithms:To draw this set of bars it uses two classes - Array and Painter.
Array contains actual sorting methods that, after any change in the list being sorted, sleep for some time with QWait() function and emit signal list_changed, connected to a draw() slot in Painter class.My problem is that Array is still sorting the list after I close the main window, and the program won't quit until the sorting is complete. I also want the stop button I put in the top left corner to be able to quit the sorting method.
I know that I need to use QThread class somehow and put Array into it but I have no knowledge about how it works (I'm pretty new to qt). I also suspect that QWait() function is probably a wrong choice for this task, but it's so easy to use and I don't know about any alternatives.Does anybody have any advice?
Thanks in advance! -
Don't use qWait() - it's not meant to be used in UI related code. Maybe even not in a separate QThread.
-
Hi,
I have a program that visualizes some sorting algorithms:To draw this set of bars it uses two classes - Array and Painter.
Array contains actual sorting methods that, after any change in the list being sorted, sleep for some time with QWait() function and emit signal list_changed, connected to a draw() slot in Painter class.My problem is that Array is still sorting the list after I close the main window, and the program won't quit until the sorting is complete. I also want the stop button I put in the top left corner to be able to quit the sorting method.
I know that I need to use QThread class somehow and put Array into it but I have no knowledge about how it works (I'm pretty new to qt). I also suspect that QWait() function is probably a wrong choice for this task, but it's so easy to use and I don't know about any alternatives.Does anybody have any advice?
Thanks in advance!@ozymohliad said in How to stop a method while it uses QWait():
sleep for some time with QWait()
Better use a QTimer for that. You can simply cancel it and then the timeout signal will not be emitted.
Also, you do not block your program.
Multi-threading is possible too, but too complicated for your case, I think