c++ - 如何将 QVariant 转换为 QJsonValue?

标签 c++ qt qjson

如何将QVariant转换为QJsonValue? 我知道 QVariant 提供了 toJsonValue 函数,但它没有按预期执行。

例如:

qDebug()<<QVariant(1.0).toJsonValue();
qDebug()<<QVariant("test").toJsonValue();

两者都返回:

QJsonValue(null)
QJsonValue(null)

期望输出:

QJsonValue(double, 1)
QJsonValue(string, "test")

最佳答案

你也可以使用这个静态函数:

QJsonValue::fromVariant( myVariant )

检查 this link了解更多信息。

关于c++ - 如何将 QVariant 转换为 QJsonValue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47709926/

相关文章:

c++ - 使用 gcov 测试 C++ 程序

c++ - 用于高性能应用程序的多线程日志记录

c++ - 全局 C++ I/O 对象是等效的还是使用 C I/O 流?

c++ - QJsonDocument::toJson() 不正确的 double

json - 在 Qt 4.7 中解析 JSON 的最简单方法

c++ - 从 JSON 字符串中获取数组时出错

c++ - 用于从麦克风捕获声音并调节音量的 API

qt - Qt模型/ View 和QTableView的基本概念

c++ - 使用Qt模拟gps数据以与traccar一起使用

c++ - 错误 : C1083: Cannot open include file: 'QJson/Parser' : No such file or directory