从 QVariantList 获取字符串

Getting strings from QVariantList

本文关键字:字符串 获取 QVariantList      更新时间:2023-10-16

来自我的数据库的数据在QVariantList中,我想遍历它并获取名字。

QVariantList sqlData = database->loadDatabase("quotes.db", "quotes");
for (int i = 1; i <= sqlData.size(); i++)
    {
        qDebug() << sqlData.value(i);
    }

这会产生:

Debug: QVariant(QVariantMap, QMap(("firstname", QVariant(QString, "Glenford") ) ( "id" ,  QVariant(qlonglong, 2) ) ( "lastname" ,  QVariant(QString, "Myers") ) ( "quote" ,  QVariant(QString, "We try to solve the problem by rushing through the design process so that enough time will be left at the end of the project to uncover errors that were made because we rushed through the design process.") ) )  ) 

如何调试"名字"的值?例如调试 = 格伦福德。

谢谢

QVariant 列表是 QVariants 的列表,对象有一个特定的迭代器。

QVariantList sqlData = database->loadDatabase("quotes.db", "quotes");
for (QVariantList::iterator j = sqlData.begin(); j != sqlData.end(); j++)
{
    qDebug() << "iterating through QVariantList ";
    qDebug() << (*j).toString(); // Print QVariant
}