基本的には
「プログラミングメモ日記 Qtのコンソールアプリの基本構造」
に書かれている通りやってみただけです(^^;)
Hello Worldプログラムです。
appmain.h
#ifndef APPMAIN_H
#define APPMAIN_H
#include <QObject>
#include <QCoreApplication>
class AppMain : public QObject
{
Q_OBJECT
public:
explicit AppMain(QObject *parent, QCoreApplication *coreApp);
signals:
public slots:
void run();
private:
QCoreApplication *app;
};
#endif // APPMAIN_H
appmain.cpp
#include "appmain.h"
AppMain::AppMain(QObject *parent, QCoreApplication *coreApp) : QObject(parent) ,app(coreApp)
{
}
void AppMain::run() {
printf("Hello World.\n");
app->quit();
}
main.cpp
#include <QCoreApplication>
#include <QTimer>
#include "appmain.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
AppMain appMain(nullptr, &a);
// QTimer::singleShot(0, &appMain, SLOT(run()));
QTimer::singleShot(0, &appMain, &AppMain::run);
return a.exec();
}
あと、こんなんでもいいかも。
main.cpp
#include <QCoreApplication>
#include <QTimer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTimer::singleShot(0, [&]()->void {
printf("Hello World\n");
a.quit();
});
return a.exec();
}
コメント