Skip to content

Commit 9c5ba84

Browse files
author
Mikhail Zolotukhin
committed
feat(qmetaobject): add null and undefined functions to QJSValue
1 parent f1dd1d4 commit 9c5ba84

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

qmetaobject/src/qtdeclarative.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,7 @@ pub fn qml_register_type<T: QObject + Default + Sized>(
506506
///
507507
/// [qt]: https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterModule
508508
#[cfg(qt_5_9)]
509-
pub fn qml_register_module(
510-
uri: &CStr,
511-
version_major: u32,
512-
version_minor: u32,
513-
) {
509+
pub fn qml_register_module(uri: &CStr, version_major: u32, version_minor: u32) {
514510
let uri_ptr = uri.as_ptr();
515511

516512
cpp!(unsafe [
@@ -937,6 +933,18 @@ pub enum QJSValueSpecialValue {
937933
}
938934

939935
impl QJSValue {
936+
pub fn null() -> Self {
937+
cpp!(unsafe [] -> QJSValue as "QJSValue" {
938+
return QJSValue(QJSValue::SpecialValue::NullValue);
939+
})
940+
}
941+
942+
pub fn undefined() -> Self {
943+
cpp!(unsafe [] -> QJSValue as "QJSValue" {
944+
return QJSValue(QJSValue::SpecialValue::UndefinedValue);
945+
})
946+
}
947+
940948
pub fn is_bool(&self) -> bool {
941949
cpp!(unsafe [self as "const QJSValue *"] -> bool as "bool" {
942950
return self->isBool();
@@ -1113,9 +1121,11 @@ mod qjsvalue_tests {
11131121
#[test]
11141122
fn test_is_undefined() {
11151123
let undefined_value = QJSValue::from(QJSValueSpecialValue::UndefinedValue);
1124+
let default_value = QJSValue::default();
11161125
let num_value = QJSValue::from(42);
11171126

11181127
assert!(undefined_value.is_undefined());
1128+
assert!(default_value.is_undefined());
11191129
assert!(!num_value.is_undefined());
11201130
}
11211131

0 commit comments

Comments
 (0)