I am running a Qt GUI program entirely within a single thread and I need to pause the program with a 'QPushbutton' and then either Resume the program at that exact point upon another 'QPushbutton' signal or Reset to a "home" state with a different 'QPushbutton' signal. I don't really have any code to show as my attempts have been misguided and entirely wrong.
Asked
Active
Viewed 173 times
1
-
Take a look at [QThread](http://doc.qt.io/qt-5/qthread.html) – IAmInPLS Mar 30 '16 at 13:36
-
2You program only thread is the main (GUI) thread. What do you want to achieve by stopping it? If you 'stop' it, you will block the GUI event loop and your application will freeze. – hank Mar 30 '16 at 13:37
-
2Are you sure you are running just a single thread ? If you are launching a QThread you have two threads, the application/event loop, and the thread managed by QThread. – perencia Mar 30 '16 at 13:39
-
I assumed I was running only one thread but this could be a misconception cause by my inexperience. I am building what is in essence a machine controller using a touch screen display. The user needs to be able to pause the machine logic to stop the machine motion. Upon hitting Resume the logic must continue where it left off. If the user chooses they can select Reset which would reset the machine to a home state and ready for a new cycle to begin. – Ryan Pensinger Mar 30 '16 at 13:45
-
Come to think of it I must be running multiple threads because I have a main.cpp and an application.cpp. Would each of these files be considered a thread in itself? – Ryan Pensinger Mar 30 '16 at 13:58
-
1No, these are not threads, just C++ translation units a.k.a source files. You really should look into state machines. Ideally, your controller should be implemented on top of a `QStateMachine`. See [this answer](http://stackoverflow.com/a/32313538/1329652) as a gentler introduction, [this one](http://stackoverflow.com/a/32595398/1329652) for a more complete communication system example, [this](http://stackoverflow.com/a/19668172/1329652) for connection state management, [this](http://stackoverflow.com/a/19150462/1329652) for use in file copy progress monitoring. – Kuba hasn't forgotten Monica Mar 30 '16 at 15:59
-
1For any sort of a machine design, you won't go very far without a good understanding of UML statecharts, since they represent hierarchical state machines that are IMHO absolutely essential in clear design and implementation of machine controllers. The [State Machine Framework documentation](http://doc.qt.io/qt-5/statemachine-api.html) is essential reading. Do it *now*. – Kuba hasn't forgotten Monica Mar 30 '16 at 16:01