c – 从QVariantList获取字符串

weixin_38050048 2019-09-12 10:37:28
我的数据库中的数据位于QVariantList中,我想循环遍历它并获取firstname. 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.") ) ) ) 我怎样才能调试“firstname”的值?例如debug = Glenford. 谢谢
...全文
578 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38072180 2019-09-12
  • 打赏
  • 举报
回复
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 }

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧