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();
@