#include#include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QThread thread; thread.start(); // Some work done by the thread... thread.quit(); // Stop the event loop of the thread, allowing for a clean exit thread.wait(); // Wait for the thread to exit return a.exec(); }
#includeIn this example, an instance of the QThread class is created and started. Some work is done by the thread before it is terminated using the terminate() method. This method will immediately stop the thread, without allowing for any cleanup or exit handling. This example demonstrates the use of the Close method explicitly through the terminate() method. Package library: Qt.#include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QThread thread; thread.start(); // Some work done by the thread... thread.terminate(); // Stop the thread immediately return a.exec(); }