Skip to content

Commit

Permalink
Fix wrong QML module lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Oct 15, 2023
1 parent 605f6cd commit ddf0b42
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 0 additions & 2 deletions application_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ void ApplicationManager::exec()
}
QObject::connect(m_engine, &QQmlEngine::exit, [this,app](const int status)
{
static jlcxx::JuliaFunction stoptimer(jl_get_function(m_qml_mod, "_stoptimer"));
stoptimer();
app->exit(status);
});
ForeignThreadManager::instance().clear(QThread::currentThread());
Expand Down
4 changes: 3 additions & 1 deletion julia_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace qmlwrap
{

jl_module_t* JuliaFunction::m_qml_mod = nullptr;

JuliaFunction::JuliaFunction(const QString& name, jl_function_t* f, QObject* parent) : QObject(parent), m_name(name), m_f(f)
{
jlcxx::protect_from_gc(m_f);
Expand All @@ -19,7 +21,7 @@ JuliaFunction::~JuliaFunction()
QVariant JuliaFunction::call(const QVariantList& args)
{
using call_julia_func_t = void* (*) (jl_value_t*, const void*);
static call_julia_func_t call_func = reinterpret_cast<call_julia_func_t>(jlcxx::unbox<void*>(jlcxx::JuliaFunction("get_julia_call", "QML")()));
static call_julia_func_t call_func = reinterpret_cast<call_julia_func_t>(jlcxx::unbox<void*>(jlcxx::JuliaFunction(jl_get_function(m_qml_mod, "get_julia_call"))()));
QVariant result_var = *reinterpret_cast<QVariant*>(call_func(m_f, &args));
return result_var;
}
Expand Down
2 changes: 2 additions & 0 deletions julia_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class JuliaFunction : public QObject
{
Q_OBJECT
public:
static jl_module_t* m_qml_mod;

JuliaFunction(const QString& name, jl_function_t* f, QObject* parent);

// Call a Julia function that takes any number of arguments as a list
Expand Down
4 changes: 3 additions & 1 deletion wrap_qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
using namespace jlcxx;

// Set pointers to Julia QML module in the classes that use it
qmlwrap::JuliaFunction::m_qml_mod = qml_module.julia_module();
qmlwrap::ApplicationManager::m_qml_mod = qml_module.julia_module();
qmlwrap::JuliaItemModel::m_qml_mod = qml_module.julia_module();
qmlwrap::MakieViewport::m_qml_mod = qml_module.julia_module();

// Enums
qml_module.add_bits<Qt::Orientation>("Orientation", jlcxx::julia_type("CppEnum"));
qml_module.set_const("Horizontal", Qt::Horizontal);
Expand Down Expand Up @@ -337,6 +338,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
qml_module.add_type<QCoreApplication>("QCoreApplication", julia_base_type<QObject>());
qml_module.add_type<QGuiApplication>("QGuiApplication", julia_base_type<QCoreApplication>())
.constructor<int&, char**>();
qml_module.method("exit", [] () { std::cout << "calling C++ exit" << std::endl; QGuiApplication::instance()->exit(); });

qml_module.add_type<QString>("QString", julia_type("AbstractString"))
.method("cppsize", &QString::size);
Expand Down

0 comments on commit ddf0b42

Please sign in to comment.