diff --git a/application_manager.cpp b/application_manager.cpp index 3b4d873..169afb4 100644 --- a/application_manager.cpp +++ b/application_manager.cpp @@ -1,5 +1,6 @@ #include "application_manager.hpp" #include "julia_api.hpp" +#include "jlcxx/functions.hpp" namespace qmlwrap { @@ -110,18 +111,6 @@ void ApplicationManager::exec() cleanup(); } -// Non-blocking exec, polling for Qt events in the uv event loop using a uv_timer_t -void ApplicationManager::exec_async() -{ - if(jl_global_event_loop() == nullptr) - { - return; - } - m_timer = new uv_timer_t(); - uv_timer_init(jl_global_event_loop(), m_timer); - uv_timer_start(m_timer, ApplicationManager::process_events, 15, 15); -} - ApplicationManager::ApplicationManager() { qInstallMessageHandler(julia_message_output); @@ -164,29 +153,18 @@ void ApplicationManager::set_engine(QQmlEngine* e) QObject::connect(m_engine, &QQmlEngine::quit, [this]() { m_quit_called = true; - if(m_timer != nullptr) - { - uv_timer_stop(m_timer); - uv_close((uv_handle_t*)m_timer, ApplicationManager::handle_quit); - } + static jlcxx::JuliaFunction stoptimer(jl_get_function(m_qml_mod, "_stoptimer")); + stoptimer(); m_app->quit(); }); } -void ApplicationManager::process_events(uv_timer_t* timer) +void ApplicationManager::process_events() { QApplication::sendPostedEvents(); QApplication::processEvents(QEventLoop::AllEvents, 15); } -void ApplicationManager::handle_quit(uv_handle_t* handle) -{ - if(instance().m_timer == nullptr) - return; - - uv_unref(handle); - delete instance().m_timer; - instance().m_timer = nullptr; -} +jl_module_t* ApplicationManager::m_qml_mod = nullptr; } diff --git a/application_manager.hpp b/application_manager.hpp index 25c2fbd..757f9f0 100644 --- a/application_manager.hpp +++ b/application_manager.hpp @@ -39,8 +39,10 @@ class ApplicationManager // Blocking call to exec, running the Qt event loop void exec(); - // Non-blocking exec, polling for Qt events in the uv event loop using a uv_timer_t - void exec_async(); + static void process_events(); + + static jl_module_t* m_qml_mod; + private: ApplicationManager(); @@ -51,14 +53,9 @@ class ApplicationManager void set_engine(QQmlEngine* e); - static void process_events(uv_timer_t* timer); - - static void handle_quit(uv_handle_t* handle); - QApplication* m_app = nullptr; QQmlEngine* m_engine = nullptr; QQmlContext* m_root_ctx = nullptr; - uv_timer_t* m_timer = nullptr; bool m_quit_called = false; }; diff --git a/wrap_qml.cpp b/wrap_qml.cpp index 95be1da..fa88e87 100644 --- a/wrap_qml.cpp +++ b/wrap_qml.cpp @@ -224,6 +224,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module) qmlRegisterType("org.julialang", 1, 0, "OpenGLViewport"); qmlRegisterType("org.julialang", 1, 0, "MakieViewport"); + qmlwrap::ApplicationManager::m_qml_mod = qml_module.julia_module(); qmlwrap::MakieViewport::m_qml_mod = qml_module.julia_module(); qml_module.add_type("QObject"); @@ -412,7 +413,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module) qml_module.method("init_qquickview", []() { return qmlwrap::ApplicationManager::instance().init_qquickview(); }); qml_module.method("qmlcontext", []() { return qmlwrap::ApplicationManager::instance().root_context(); }); qml_module.method("exec", []() { qmlwrap::ApplicationManager::instance().exec(); }); - qml_module.method("exec_async", []() { qmlwrap::ApplicationManager::instance().exec_async(); }); + qml_module.method("process_events", qmlwrap::ApplicationManager::process_events); qml_module.add_type("QTimer", julia_base_type()) .method("start", [] (QTimer& t) { t.start(); } )