Created
April 16, 2023 17:49
-
-
Save b-epelbaum/24a23826c2145d2a2b1e2ab487fe12e6 to your computer and use it in GitHub Desktop.
A simple console Qt application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // main.cpp | |
| #include <QtCore> | |
| class Task : public QObject | |
| { | |
| Q_OBJECT | |
| public: | |
| Task(QObject *parent = 0) : QObject(parent) {} | |
| public slots: | |
| void run() | |
| { | |
| // Do processing here | |
| emit finished(); | |
| } | |
| signals: | |
| void finished(); | |
| }; | |
| #include "main.moc" | |
| int main(int argc, char *argv[]) | |
| { | |
| QCoreApplication a(argc, argv); | |
| // Task parented to the application so that it | |
| // will be deleted by the application. | |
| Task *task = new Task(&a); | |
| // This will cause the application to exit when | |
| // the task signals finished. | |
| QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit())); | |
| // This will run the task from the application event loop. | |
| QTimer::singleShot(0, task, SLOT(run())); | |
| return a.exec(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment