Skip to content

Commit

Permalink
Implement QMetaType for QStringList.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush1325 committed Mar 9, 2022
1 parent 3dd450b commit d91f074
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions qmetaobject/src/qmetatype.rs
Expand Up @@ -494,6 +494,7 @@ qdeclare_builtin_metatype! {QJsonArray => 47}
qdeclare_builtin_metatype! {QPixmap => if cfg!(qt_6_0) { 0x1001 } else { 65 }}
qdeclare_builtin_metatype! {QColor => if cfg!(qt_6_0) { 0x1003 } else { 67 }}
qdeclare_builtin_metatype! {QImage => if cfg!(qt_6_0) { 0x1006 } else { 70 }}
qdeclare_builtin_metatype! {QStringList => 11}

#[cfg(target_pointer_width = "32")]
qdeclare_builtin_metatype! {isize => 2} // That's QMetaType::Int
Expand Down Expand Up @@ -664,4 +665,13 @@ mod tests {
Some(QSize { width: 123, height: 254 })
);
}

#[test]
fn test_qvariant_qstringlist() {
let list = QStringList::from(["abc", "def"]);
let t = QVariant::from(list.clone());

assert!(t == list.to_qvariant());
assert!(QStringList::from_qvariant(t).unwrap() == list);
}
}
12 changes: 12 additions & 0 deletions qttypes/src/lib.rs
Expand Up @@ -636,6 +636,18 @@ impl From<QVariantList> for QVariant {
})
}
}

impl From<QStringList> for QVariant {
/// Wrapper around [`QVariant(const QStringList &)`][ctor] constructor.
///
/// [ctor]: https://doc.qt.io/qt-5/qvariant.html#QVariant-16
fn from(a: QStringList) -> Self {
cpp!(unsafe [a as "QStringList"] -> QVariant as "QVariant" {
return QVariant(a);
})
}
}

impl From<i32> for QVariant {
/// Wrapper around [`QVariant(int)`][ctor] constructor.
///
Expand Down

0 comments on commit d91f074

Please sign in to comment.