Skip to content
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

Add null QVariant constructor #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading