-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cxx-qt-lib: Add binding for QQmlApplicationEngine::singletonInstance #1140
base: main
Are you sure you want to change the base?
cxx-qt-lib: Add binding for QQmlApplicationEngine::singletonInstance #1140
Conversation
void* | ||
qqmlapplicationengineSingletonInstance(QQmlApplicationEngine& engine, QAnyStringView uri, QAnyStringView typeName) | ||
{ | ||
return reinterpret_cast<void*>(engine.singletonInstance<QObject*>(uri, typeName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of hate everything about this, but this somehow works. Suggestions appreciated, since I don't know of any other method supported in cxx-qt that has a template parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, once we have up/down casting and QObject already as a type #562 then this would be much easier. We would like this have this implemented in this cycle as it seems useful in multiple places.
It would be return a pointer to a QObject, then use the downcast_ptr method to get your original type back.
02a5168
to
3a86460
Compare
3a86460
to
1f6d532
Compare
This allows accessing QObject singleton instances registered in the QML engine (using #[qml_singleton]) from the Rust side.
1f6d532
to
55647b9
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1140 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 71
Lines 11967 11967
=========================================
Hits 11967 11967 ☔ View full report in Codecov by Sentry. |
@@ -79,13 +82,33 @@ mod ffi { | |||
) -> Pin<&mut QQmlEngine>; | |||
} | |||
|
|||
#[cfg(any(cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5))] | |||
unsafe extern "C++" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This #[cfg] doesn't work I guess, so Qt5 and <6.5 builds will fail. A possible solution could be to separate this into a different cxx::bridge as suggested in this issue but that seems extreme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows accessing QObject singleton instances registered in the QML engine (using #[qml_singleton]) from the Rust side.