22 #include<QCoreApplication> 23 #include<QNetworkAccessManager> 24 #include<QNetworkRequest> 25 #include<QNetworkReply> 33 QCoreApplication* app =
nullptr;
46 static QEvent::Type event_type =
static_cast<QEvent::Type
>(QEvent::registerEventType());
67 promise.set_exception(std::current_exception());
73 return promise.get_future();
77 std::function<void()> task;
78 std::promise<void> promise;
97 app =
new QCoreApplication(argc, argv);
119 return QObject::event(e);
132 void build_and_run(
int argc,
char** argv,
const std::function<
void()>& ready)
134 QThread::currentThread();
135 if (QCoreApplication::instance() !=
nullptr)
136 throw std::runtime_error(
137 "qt::core::world::build_and_run: " 138 "There is already a QCoreApplication running.");
159 QEventLoopLocker locker;
160 }).wait_for(std::chrono::seconds{1});
165 QCoreApplication* instance = QCoreApplication::instance();
169 throw std::runtime_error(
"Qt world has not been built before calling this function.");
186 #include "qtbridge.moc" TaskHandler(QObject *parent)
void destroyCoreApplicationInstace()
QEvent::Type qt_core_world_task_event_type()
void destroy()
Destroys the Qt core world and quits its event loop.
QCoreApplication * coreApplicationInstance()
void build_and_run(int argc, char **argv, const std::function< void()> &ready)
Sets up the Qt core world and executes its event loop. Blocks until destroy() is called.
void createCoreApplicationInstanceWithArgs(int argc, char **argv)
TaskEvent(const std::function< void()> &task)
std::future< void > get_future()
TaskHandler * task_handler()
std::future< void > enter_with_task(const std::function< void()> &task)
Enters the Qt core world and schedules the given task for execution.