- 
    
Bug
 - 
    Resolution: Done
 - 
    
P2: Important
 - 
    5.10.0
 - 
    None
 - 
    Windows 10 x64, MSVC 2015 x86
 
- 
        5944c2503c8515903dae3a0400fd50a8eafa8276
 
Summary
 Q(Tree|Table|List)View displays QJsonValue::String, but not QJsonValue::Bool or QJsonValue::Double
Code to Reproduce
// testmodel.h #ifndef TESTMODEL_H #define TESTMODEL_H #include <QAbstractListModel> #include <QJsonValue> class TestModel : public QAbstractListModel { Q_OBJECT QVariantList m_data; public: TestModel(QObject *parent = nullptr) : QAbstractListModel(parent) { m_data = QVariantList{ true, 3.14159, "Hello", QJsonValue(true), QJsonValue(3.14159), QJsonValue("Hello") }; } int rowCount(const QModelIndex&) const override { return m_data.count(); } QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override { if (role == Qt::DisplayRole && index.row() >= 0 && index.row() < m_data.count()) return m_data[index.row()]; return QVariant(); } }; #endif // TESTMODEL_H
// main.cpp #include "testmodel.h" #include <QApplication> #include <QListView> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); TestModel model; for (int i = 0; i < model.rowCount(QModelIndex()); ++i) qDebug() << model.data(model.index(i)); QListView view; view.setModel(&model); view.show(); return a.exec(); }
Debug Output
This shows that the 6 data items have been created correctly – 3 raw QVariants plus 3 copies of the same data wrapped in QJsonValue:
QVariant(bool, true) QVariant(double, 3.14159) QVariant(QString, "Hello") QVariant(QJsonValue, QJsonValue(bool, true)) QVariant(QJsonValue, QJsonValue(double, 3.14159)) QVariant(QJsonValue, QJsonValue(string, "Hello"))
Expected QListView Text
- true
 - 3.14159
 - Hello
 - true
 - 3.14159
 - Hello
 
Actual QListView Text
- true
 - 3.14159
 - Hello
 - Hello