One listview, multiple XmlListModels
-
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.
-
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) -
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.
-
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();
@