Forums

OverviewFelgo 2 Support (Qt 5) › including messenger backend into QML code

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18766

    Felgo User

     
    <div class=”content”>

    Hello Guys,

    </div>
    maybe i get here a solution of my problem.

     
    <div class=”content”>

    i´ve tried to put my own backend c++ code in a QML model, it´s from the v-play messenger example.
    i write a new class with this code:

    class DataObject : public QObject
    {
        Q_OBJECT
    
        Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
        Q_PROPERTY(QString detailText READ detailText WRITE setDetailText NOTIFY detailTextChanged)
     ...
    

    i add then with:
    QList dataList;
    dataList.append(new DataObject(chat->kon[i]->getname(), QVariant(ia).toString()));

    a new QList.

    so far so good.
    Now i add in the main.cpp with:

    engine.rootContext()->setContextProperty(“modelContact”, QVariant::fromValue(cont->dataList));

    a modelContact property.

    so in the example code it´s in the qml code the following area that i want to change:

    // Model should be loaded from your messaging backend
            //  model: [
            //    { text: "Tom McEloy", detailText: "Sorry for the late reply ...", image: Qt.resolvedUrl("../../assets/portrait0.jpg") },
            //    { text: "Leah Douglas", detailText: "Hahaha :D", image: Qt.resolvedUrl("../../assets/portrait1.jpg") }
            //  ]
    

    so like the comment i want to load the model from the backend, so i try:

    model: modelContact
    

    but i get no text or detailtext, where is the problem?

    </div>

    #18770

    Günther
    Felgo Team

    Hi,

    are you using the SimpleRow type for showing your list entries?

    The SimpleRow only supports auto-detection of properties like text, detailText, etc… for array-based models (as in the QML example).
    For other list models, you can manually set the properties of the SimpleRow delegate to some properties of your model.

    See Models and Views with Qt Quick for more information on working with model/delegates in QML.

    Best,
    Günther

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support