Qt中Model与List的使用

本文介绍Qt编程中,Model作为QAbstractItemModel的子类,与List(QMediaPlaylist)的结合使用。Model不直接存储数据,而是通过内部的List成员和值对表QMap来管理和提供数据访问。当使用Model时,需先设置List,然后通过Model提供的接口(如rowCount、columnCount、index、parent、data和setData等)来操作和获取数据。此外,还讨论了Model在数据变更时需调用的保护函数,如beginResetModel、endResetModel、beginInsertRows、endInsertRows和beginRemoveRows、endRemoveRows。
摘要由CSDN通过智能技术生成

class PlaylistModel : public QAbstractItemModel
{
  
    Q_OBJECT
 
public:
    enum Column
    {
  
        Title = 0,
        ColumnCount
    };
 
    PlaylistModel(QObject *parent = 0);
 
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &child) const;
 
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
    QMediaPlaylist *playlist() const;
    void setPlaylist(QMediaPlaylist *playlist);
 
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值