Created
November 3, 2013 15:33
-
-
Save silvercircle/7291487 to your computer and use it in GitHub Desktop.
Console app in Qt with a QCoreApplication (just a personal note...)
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
#include <QCoreApplication> | |
#include <worker.h> | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
Worker *w = new Worker(&a); | |
QObject::connect(w, SIGNAL(finished()), &a, SLOT(quit())); | |
QTimer::singleShot(0, w, SLOT(run())); // launch it | |
return a.exec(); | |
} | |
// worker.cpp | |
#include <QtCore> | |
#include <QString> | |
#include <worker.h> | |
#include <memory> | |
void Worker::run() { | |
printf("Hello world...\n\n"); | |
emit finished(); | |
} | |
// worker.h | |
#ifndef WORKER_H | |
#define WORKER_H | |
#include <QtCore> | |
class Worker : public QObject { | |
Q_OBJECT | |
public: | |
Worker(QObject *parent = 0) : QObject(parent) {} | |
public slots: | |
void run(); | |
signals: | |
void finished(); | |
}; | |
#endif // WORKER_H | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment