Skip to content

Commit

Permalink
Add null QVariant constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Aug 5, 2024
1 parent 84badb6 commit 9fe1dc3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qttypes/src/qtcore/qvariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl QVariant {
})
}

/// Return a `null` QVariant, in contrast to `default()` which returns an `undefined` QVariant.
pub fn null() -> QVariant {
cpp!(unsafe [] -> QVariant as "QVariant" {
return QJsonValue().toVariant();
})
}

// FIXME: do more wrappers
}

Expand Down Expand Up @@ -293,4 +300,15 @@ mod tests {
assert_eq!(qv.to_int(), 313);
assert_eq!(format!("{:?}", qv), "QVariant(int: \"313\")");
}

#[test]
fn qvariant_null() {
let qv_undefined = QVariant::default();
assert!(qv_undefined.is_null());
assert!(!qv_undefined.is_valid());

let qv_null = QVariant::null();
assert!(qv_null.is_null());
assert!(qv_null.is_valid());
}
}

0 comments on commit 9fe1dc3

Please sign in to comment.