Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. One listview, multiple XmlListModels
Forum Updated to NodeBB v4.3 + New Features

One listview, multiple XmlListModels

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtdeveloper1
    wrote on last edited by
    #1

    Hi,

    i searched the forum but didn't find anything that fits to my problem. Is it possible to have more than one XmlListModel attached to a listview?

    Do i have to make something with c++ or is it possible with qml?

    Thank you.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      remy_david
      wrote on last edited by
      #2

      A list can only have 1 model, what will it do if your 2 models do not have the same number of rows ?
      You can either use C++ to merge your 2 XML into one model and expose it to QML or bind one XmlListModel to the list and access the other manually using XmlListModel.get(index)

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtdeveloper1
        wrote on last edited by
        #3

        Hi,

        thank you for your answer. both models are having a "link" tag, so i thought i could bind them and query it.

        Anyway i am already making a custom model (merging them) and make it available to qml.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qtdeveloper1
          wrote on last edited by
          #4

          Ok i have an other related question.

          I have so far:

          • A new Model which extends QAbstractListModel.
          • QNetworkAccessManager requests (get) in the constructor.
          • A "replyFinished" slot, where i parse the requests with QXmlStreamReader
          • Add the Data to the Model (QList<News>) (in the replyfinished).
          • News is just simple a class for link,pubdate,description and headline

          this is my model
          @
          class NewsModel : public QAbstractListModel
          {
          Q_OBJECT
          public:
          enum NewsRoles
          {
          LinkRole = Qt::UserRole + 1,
          DescriptionRole,
          DateRole,
          HeadLineRole
          };

              NewsModel(QObject *parent = 0);
              void addNews(const News &news);
              int rowCount(const QModelIndex & parent = QModelIndex()) const;
              QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
          public slots:
              void replyFinished(QNetworkReply* reply);
          private:
              QList<News> m_news;
          

          };
          @

          if i add news on startup than they are shown in the listview, but not the one i put in the model manually (edit: not manually, through the QNetworkAccessManager in the replyfinished method).
          @
          NewsModel newsModel;
          newsModel.addNews(News("www.test.com","test","test","test"));
          view.rootContext()->setContextProperty("newsmodel", &newsModel);
          @

          Do i have to fire a event? Or am i missing a method?

          EDIT:

          I just had to look into the addNews method, which was working, so you don't need to fire a event:
          @
          beginInsertRows(QModelIndex(), rowCount(), rowCount());
          m_news.append(News("1","2","3","4"));
          endInsertRows();
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved