Skip to content

Commit

Permalink
Add QVariant::toInt wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Feb 23, 2024
1 parent 1656722 commit 39824c7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions qttypes/src/qtcore/qvariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ impl QVariant {
})
}

/// Wrapper around [`toInt()`][method] method.
///
/// [method]: https://doc.qt.io/qt-5/qvariant.html#toInt
pub fn to_int(&self) -> u32 {
cpp!(unsafe [self as "const QVariant*"] -> u32 as "int" {
return self->toInt();
})
}

/// Wrapper around ['typeName()`][method] method.
///
/// [method]: https://doc.qt.io/qt-5/qvariant.html#typeName
Expand Down Expand Up @@ -277,4 +286,11 @@ mod tests {
assert_eq!(qv.to_qstring().to_string(), String::from("false"));
assert_eq!(format!("{:?}", qv), "QVariant(bool: \"false\")");
}

#[test]
fn qvariant_debug_int() {
let qv = QVariant::from(313);
assert_eq!(qv.to_int(), 313);
assert_eq!(format!("{:?}", qv), "QVariant(int: \"313\")");
}
}

0 comments on commit 39824c7

Please sign in to comment.