Skip to content

Expose a list of your customized C++ data structure to QML, easily access data from C++ and QML both sides.

Notifications You must be signed in to change notification settings

arkceajin/QmlListModel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

QmlListModel

This is a Abandoned repository, I made a smailiar one QmlObjectList

Expose a list of your customized C++ data structure to QML, easily access data from C++ and QML both sides.

How to add QmlListModel in your project

  1. Put QmlListModel.h into your project, add it into .pro , and enable C++11 by adding QMAKE_CXXFLAGS += -std=c++11.

  2. Create your data class which derivers from QObject.

class Apartment : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString name MEMBER mName)
public:
    QString mName;
}
  1. Create the list model class which derivers from QmlListModel<Data>, adding Q_OBJECT and QML_LIST_MODEL macro in the header of data model class.
#include "QmlListModel.h"

class CompanyModel : public QmlListModel<Apartment>
{
    Q_OBJECT
    QML_LIST_MODEL
};
  1. Registers module by qmlRegisterType.

Using in C++ side

  1. The QmlListModel provides getData appendData etc. functions to accessing the data list.

  2. Serialize and unserialize it into QByteArray or JSON.

Using in QML side

  1. Display data using Repeater or ListView

  2. Access the data in JavaScript.

Demo

The QmlListModelDemo create a nested data structrue like this:

CompanyModel
├── Apartment 1
│   ├── Member A
│   └── Member B
├── Apartment 2
│   ├── Member C
│   ├── Member D
│   └── Member E
└── Apartment 3

About

Expose a list of your customized C++ data structure to QML, easily access data from C++ and QML both sides.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published