File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,17 @@ impl QVariant {
94
94
} )
95
95
}
96
96
97
+ /// Return a `null` QVariant, in contrast to `default()` which returns an `undefined` QVariant.
98
+ pub fn null ( ) -> QVariant {
99
+ cpp ! ( unsafe [ ] -> QVariant as "QVariant" {
100
+ #if QT_VERSION < QT_VERSION_CHECK ( 6 , 0 , 0 )
101
+ return QJsonValue ( ) . toVariant( ) ;
102
+ #else
103
+ return QVariant :: fromValue( nullptr) ;
104
+ #endif
105
+ } )
106
+ }
107
+
97
108
// FIXME: do more wrappers
98
109
}
99
110
@@ -304,4 +315,15 @@ mod tests {
304
315
assert_eq ! ( qv. to_int( ) , 313 ) ;
305
316
assert_eq ! ( format!( "{:?}" , qv) , "QVariant(int: \" 313\" )" ) ;
306
317
}
318
+
319
+ #[ test]
320
+ fn qvariant_null ( ) {
321
+ let qv_undefined = QVariant :: default ( ) ;
322
+ assert ! ( qv_undefined. is_null( ) ) ;
323
+ assert ! ( !qv_undefined. is_valid( ) ) ;
324
+
325
+ let qv_null = QVariant :: null ( ) ;
326
+ assert ! ( qv_null. is_null( ) ) ;
327
+ assert ! ( qv_null. is_valid( ) ) ;
328
+ }
307
329
}
You can’t perform that action at this time.
0 commit comments