I'm sending a QList from C++ to QML using signal/slot
The data is populated from a call to an external API server and after parsing the data and adding them to a QList, I emit a signal with the list, and I handle it in qml file.
{
qDebug() << "Get players...";
QJsonObject obj = doc.object();
auto status = obj["status"].toBool();
auto players = obj["players"].toArray();
QList<Player*> ps;
foreach (const QJsonValue & v, players)
{
auto obj = v.toObject();
auto player = obj["player"].toObject();
auto p = new Player();
p->setId(player["id"].toString().toInt());
p->setName(player["name"].toString());
ps.append(p);
}
qDebug() << "got players: " << ps.count(); //this prints 4000
emit gotPlayers(status, ps);
}
The signal is defined like this
signals:
void gotPlayers(bool status, QList<Player *> players);
in QML file, this is what I have
Connections {
target: APIConnection
onGotPlayers: {
console.log(players);
}
}
When onGotPlayers
is called for the first time, it always prints
qml: undefined
and on any other subsequent call after that it will print
qml: QVariant(QList<Player*>)
Any suggestions on why this is happening? I know of a bug in 5.11, but I'm using 5.9.5 with MSVC2015 32 bit. does that affect