Note: this answer uses other functions to convert them, which you may consider.
You can use QDataStream to serialize QPair to QByteArray , and then convert it to QVariant , and you can reverse process to get QPair from QVariant .
Example:
//Convert the QPair to QByteArray first and then //convert it to QVariant QVariant tovariant(const QPair<int, int> &value) { QByteArray ba; QDataStream stream(&ba, QIODevice::WriteOnly); stream << value; return QVariant(ba); } //Convert the QVariant to QByteArray first and then //convert it to QPair QPair<int, int> topair(const QVariant &value) { QPair<int, int> pair; QByteArray ba = value.toByteArray(); QDataStream stream(&ba, QIODevice::ReadOnly); stream >> pair; return pair; }
source share