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 @@ -93,6 +93,17 @@ impl QVariant {
93
93
} )
94
94
}
95
95
96
+ /// Return a `null` QVariant, in contrast to `default()` which returns an `undefined` QVariant.
97
+ pub fn null ( ) -> QVariant {
98
+ cpp ! ( unsafe [ ] -> QVariant as "QVariant" {
99
+ #if QT_VERSION < QT_VERSION_CHECK ( 6 , 0 , 0 )
100
+ return QJsonValue ( ) . toVariant( ) ;
101
+ #else
102
+ return QVariant :: fromValue( nullptr) ;
103
+ #endif
104
+ } )
105
+ }
106
+
96
107
// FIXME: do more wrappers
97
108
}
98
109
@@ -293,4 +304,15 @@ mod tests {
293
304
assert_eq ! ( qv. to_int( ) , 313 ) ;
294
305
assert_eq ! ( format!( "{:?}" , qv) , "QVariant(int: \" 313\" )" ) ;
295
306
}
307
+
308
+ #[ test]
309
+ fn qvariant_null ( ) {
310
+ let qv_undefined = QVariant :: default ( ) ;
311
+ assert ! ( qv_undefined. is_null( ) ) ;
312
+ assert ! ( !qv_undefined. is_valid( ) ) ;
313
+
314
+ let qv_null = QVariant :: null ( ) ;
315
+ assert ! ( qv_null. is_null( ) ) ;
316
+ assert ! ( qv_null. is_valid( ) ) ;
317
+ }
296
318
}
You can’t perform that action at this time.
0 commit comments