Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main (...)
- SomeList someList;
- QScopedPointer<QApplication> app(Sailfish::createApplication(argc, argv));
- QDeclarativeView view;
- view.engine()->rootContext()->setContextProperty("somelistmodel", &someList);
- view.setSource(QUrl(QString(DEPLOYMENT_PATH) + "/main.qml"));
- view.show();
- return app->exec();
- // somelist.h
- enum
- {
- TitleRole = Qt::UserRole + 1
- };
- class SomeList: public QAbstractListModel
- {
- public:
- SomeList()
- {
- titles.append("1test");
- titles.append("2test");
- titles.append("3test");
- titles.append("4test");
- }
- int rowCount(const QModelIndex &parent) const
- {
- return titles.count();
- }
- QVariant data(const QModelIndex &index, int role) const
- {
- switch(role)
- {
- case TitleRole:
- return titles.at(index.row());
- default:
- return QVariant();
- }
- }
- const QHash<int, QByteArray> roleNames()
- {
- QHash<int, QByteArray> roles;
- roles.insert(TitleRole, "title");
- return roles;
- }
- private:
- QList<QString> titles;
- };
- // main.qml
- ApplicationWindow
- {
- initialPage: Page
- {
- ListView{
- anchors.fill: parent
- model: somelistmodel
- delegate: Text{
- text: title
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement