22 #include<QCoreApplication> 23 #include<QNetworkAccessManager> 24 #include<QNetworkRequest> 25 #include<QNetworkReply> 31 QCoreApplication* app =
nullptr;
44 static QEvent::Type event_type =
static_cast<QEvent::Type
>(QEvent::registerEventType());
65 promise.set_exception(std::current_exception());
71 return promise.get_future();
75 std::function<void()> task;
76 std::promise<void> promise;
95 app =
new QCoreApplication(argc, argv);
117 return QObject::event(e);
130 void build_and_run(
int argc,
char** argv,
const std::function<
void()>& ready)
132 QThread::currentThread();
133 if (QCoreApplication::instance() !=
nullptr)
134 throw std::runtime_error(
135 "qt::core::world::build_and_run: " 136 "There is already a QCoreApplication running.");
157 QEventLoopLocker locker;
158 }).wait_for(std::chrono::seconds{1});
163 QCoreApplication* instance = QCoreApplication::instance();
167 throw std::runtime_error(
"Qt world has not been built before calling this function.");
184 #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.