Skip to content

Instantly share code, notes, and snippets.

@silvercircle
Created November 3, 2013 15:33
Show Gist options
  • Save silvercircle/7291487 to your computer and use it in GitHub Desktop.
Save silvercircle/7291487 to your computer and use it in GitHub Desktop.
Console app in Qt with a QCoreApplication (just a personal note...)
#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