Skip to content

Commit

Permalink
impl From<QVariantMap> for QVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos authored and ogoffart committed Aug 7, 2024
1 parent 84badb6 commit b08463a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions qttypes/src/qtcore/qvariant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::fmt;

use crate::{
cpp, cpp_class, QByteArray, QDate, QDateTime, QString, QStringList, QTime, QUrl, QVariantList, QVariantMap
cpp, cpp_class, QByteArray, QDate, QDateTime, QString, QStringList, QTime, QUrl, QVariantList,
QVariantMap,
};

cpp_class!(
Expand Down Expand Up @@ -118,6 +119,16 @@ impl From<QString> for QVariant {
})
}
}
impl From<QVariantMap> for QVariant {
/// Wrapper around [`QVariant(const QMap<QString, QVariant> &)`][ctor] constructor.
///
/// [ctor]: https://doc.qt.io/qt-5/qvariant.html#QVariant-22
fn from(a: QVariantMap) -> QVariant {
cpp!(unsafe [a as "QVariantMap"] -> QVariant as "QVariant" {
return QVariant(a);
})
}
}
impl From<QByteArray> for QVariant {
/// Wrapper around [`QVariant(const QByteArray &)`][ctor] constructor.
///
Expand Down Expand Up @@ -293,4 +304,4 @@ mod tests {
assert_eq!(qv.to_int(), 313);
assert_eq!(format!("{:?}", qv), "QVariant(int: \"313\")");
}
}
}

0 comments on commit b08463a

Please sign in to comment.