QT Learning Pathway (46): Custom model of the second 2010-01-19 00:35:56 tags: qt c + + qt Tutorial Tutorial original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://devbean.blog.51cto.com/448512/267972 The previous example has given a clearer way to customize the model, which is to cover the few functions we need. However, the previous example is simply a presentation of data, which means that the data is read-only. So how can you read and write data? That's the example of coming in. This example is also from C++gui programming with Qt 4, 2nd edition this book. Let's look at the code first: Citymodel.h class Citymodel:public Qabstracttablemodel
{
Q_object
Public
Citymodel (Qobject *parent = 0);
void setcities (const qstringlist &citynames);
int RowCount (const qmodelindex &parent) const;
int ColumnCount (const qmodelindex &parent) const;
Qvariant data (const QMODELINDEX &index, int role) const;
BOOL SetData (const qmodelindex &index, const qvariant &value, int role);
qvariant headerdata (int section, qt::orientation Orientation, int role) const;
Qt::itemflags flags (const QMODELINDEX &index) const;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.