QList sent from C++ and recived in QML is undefined












2















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










share|improve this question























  • You can either convert your Player to some sort of QJsonObject or you'll need to register your type with qml using qmlRegisterType. The fields will also need to be properties or have Q_INVOKABLE member functions to access the data. I recommend going the qmlRegisterType way, or you will spend a lot of time converting between QJsonObjects and your native C++ class.

    – Ross Rogers
    Jan 2 at 18:38













  • You probably didn't register the Player type. Also I advice you to pass the array as QVariantList instead of QList. As I remember QML supports only simple types in lists. See this documents fo more info.

    – folibis
    Jan 2 at 19:47













  • I actually did register it. qmlRegisterType<PlayerModel>("com.Game.PlayerModel", 1, 0, "PlayerModel"); and qmlRegisterType<Player>("com.Game.Player", 1, 0, "Player");

    – user3113652
    Jan 2 at 19:59













  • @folibis I will do try to use QVariantList instead of QList and see if will solve my problem.

    – user3113652
    Jan 2 at 20:01






  • 1





    Shouldn't you register Player * instead of Player?

    – folibis
    Jan 3 at 5:39
















2















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










share|improve this question























  • You can either convert your Player to some sort of QJsonObject or you'll need to register your type with qml using qmlRegisterType. The fields will also need to be properties or have Q_INVOKABLE member functions to access the data. I recommend going the qmlRegisterType way, or you will spend a lot of time converting between QJsonObjects and your native C++ class.

    – Ross Rogers
    Jan 2 at 18:38













  • You probably didn't register the Player type. Also I advice you to pass the array as QVariantList instead of QList. As I remember QML supports only simple types in lists. See this documents fo more info.

    – folibis
    Jan 2 at 19:47













  • I actually did register it. qmlRegisterType<PlayerModel>("com.Game.PlayerModel", 1, 0, "PlayerModel"); and qmlRegisterType<Player>("com.Game.Player", 1, 0, "Player");

    – user3113652
    Jan 2 at 19:59













  • @folibis I will do try to use QVariantList instead of QList and see if will solve my problem.

    – user3113652
    Jan 2 at 20:01






  • 1





    Shouldn't you register Player * instead of Player?

    – folibis
    Jan 3 at 5:39














2












2








2








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










share|improve this question














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







qt qml qt5






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 18:07









user3113652user3113652

468




468













  • You can either convert your Player to some sort of QJsonObject or you'll need to register your type with qml using qmlRegisterType. The fields will also need to be properties or have Q_INVOKABLE member functions to access the data. I recommend going the qmlRegisterType way, or you will spend a lot of time converting between QJsonObjects and your native C++ class.

    – Ross Rogers
    Jan 2 at 18:38













  • You probably didn't register the Player type. Also I advice you to pass the array as QVariantList instead of QList. As I remember QML supports only simple types in lists. See this documents fo more info.

    – folibis
    Jan 2 at 19:47













  • I actually did register it. qmlRegisterType<PlayerModel>("com.Game.PlayerModel", 1, 0, "PlayerModel"); and qmlRegisterType<Player>("com.Game.Player", 1, 0, "Player");

    – user3113652
    Jan 2 at 19:59













  • @folibis I will do try to use QVariantList instead of QList and see if will solve my problem.

    – user3113652
    Jan 2 at 20:01






  • 1





    Shouldn't you register Player * instead of Player?

    – folibis
    Jan 3 at 5:39



















  • You can either convert your Player to some sort of QJsonObject or you'll need to register your type with qml using qmlRegisterType. The fields will also need to be properties or have Q_INVOKABLE member functions to access the data. I recommend going the qmlRegisterType way, or you will spend a lot of time converting between QJsonObjects and your native C++ class.

    – Ross Rogers
    Jan 2 at 18:38













  • You probably didn't register the Player type. Also I advice you to pass the array as QVariantList instead of QList. As I remember QML supports only simple types in lists. See this documents fo more info.

    – folibis
    Jan 2 at 19:47













  • I actually did register it. qmlRegisterType<PlayerModel>("com.Game.PlayerModel", 1, 0, "PlayerModel"); and qmlRegisterType<Player>("com.Game.Player", 1, 0, "Player");

    – user3113652
    Jan 2 at 19:59













  • @folibis I will do try to use QVariantList instead of QList and see if will solve my problem.

    – user3113652
    Jan 2 at 20:01






  • 1





    Shouldn't you register Player * instead of Player?

    – folibis
    Jan 3 at 5:39

















You can either convert your Player to some sort of QJsonObject or you'll need to register your type with qml using qmlRegisterType. The fields will also need to be properties or have Q_INVOKABLE member functions to access the data. I recommend going the qmlRegisterType way, or you will spend a lot of time converting between QJsonObjects and your native C++ class.

– Ross Rogers
Jan 2 at 18:38







You can either convert your Player to some sort of QJsonObject or you'll need to register your type with qml using qmlRegisterType. The fields will also need to be properties or have Q_INVOKABLE member functions to access the data. I recommend going the qmlRegisterType way, or you will spend a lot of time converting between QJsonObjects and your native C++ class.

– Ross Rogers
Jan 2 at 18:38















You probably didn't register the Player type. Also I advice you to pass the array as QVariantList instead of QList. As I remember QML supports only simple types in lists. See this documents fo more info.

– folibis
Jan 2 at 19:47







You probably didn't register the Player type. Also I advice you to pass the array as QVariantList instead of QList. As I remember QML supports only simple types in lists. See this documents fo more info.

– folibis
Jan 2 at 19:47















I actually did register it. qmlRegisterType<PlayerModel>("com.Game.PlayerModel", 1, 0, "PlayerModel"); and qmlRegisterType<Player>("com.Game.Player", 1, 0, "Player");

– user3113652
Jan 2 at 19:59







I actually did register it. qmlRegisterType<PlayerModel>("com.Game.PlayerModel", 1, 0, "PlayerModel"); and qmlRegisterType<Player>("com.Game.Player", 1, 0, "Player");

– user3113652
Jan 2 at 19:59















@folibis I will do try to use QVariantList instead of QList and see if will solve my problem.

– user3113652
Jan 2 at 20:01





@folibis I will do try to use QVariantList instead of QList and see if will solve my problem.

– user3113652
Jan 2 at 20:01




1




1





Shouldn't you register Player * instead of Player?

– folibis
Jan 3 at 5:39





Shouldn't you register Player * instead of Player?

– folibis
Jan 3 at 5:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011117%2fqlistqobject-sent-from-c-and-recived-in-qml-is-undefined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011117%2fqlistqobject-sent-from-c-and-recived-in-qml-is-undefined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas