Reputation: 24061
Data from my DB is in a QVariantList and I want to loop through it and get firstname out.
QVariantList sqlData = database->loadDatabase("quotes.db", "quotes");
for (int i = 1; i <= sqlData.size(); i++)
{
qDebug() << sqlData.value(i);
}
This produces:
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.") ) ) )
How can I just debug the value of "firstname"? Eg debug = Glenford.
Thanks
Upvotes: 3
Views: 14951
Reputation: 663
QVariant list is a list of QVariants, the object has a specific iterator for it.
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
}
Upvotes: 5