이 페이지에서

QAbstractListModel Class

QAbstractListModel 클래스는 1차원 목록 모델을 생성하기 위해 하위 클래스로 확장할 수 있는 추상 모델을 제공합니다. 더 보기...

헤더: #include <QAbstractListModel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
상속: QAbstractItemModel
상속받는 클래스:

QPdfLinkModel, QPdfSearchModel, QStringListModel, QVirtualKeyboardSelectionListModel 및 QWebEngineHistoryModel

공개 함수

QAbstractListModel(QObject *parent = nullptr)
virtual ~QAbstractListModel()

재구현된 공용 함수

virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override
virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const override

상세 설명

QAbstractListModel은 데이터를 단순한 비계층적 항목 시퀀스로 표현하는 모델에 대한 표준 인터페이스를 제공합니다. 이 클래스는 직접 사용되지 않으며, 반드시 하위 클래스로 구현되어야 합니다.

이 모델은 ` QAbstractItemModel`보다 더 특화된 인터페이스를 제공하므로 트리 뷰와 함께 사용하기에는 적합하지 않습니다. 해당 용도로 모델을 제공하려면 ` QAbstractItemModel `을 상속받아 서브클래스를 만들어야 합니다. 데이터를 관리하기 위해 여러 개의 리스트 모델을 사용해야 하는 경우, 대신 ` QAbstractTableModel `을 상속받아 서브클래스를 만드는 것이 더 적절할 수 있습니다.

이 클래스를 상속받고 필수 함수를 최소한으로 구현하면 간단한 모델을 만들 수 있습니다. 예를 들어, QListView 위젯에 문자열 목록을 제공하는 간단한 읽기 전용 QStringList 기반 모델을 구현할 수 있습니다. 이 경우, 목록에 포함된 항목의 수를 반환하는 rowCount() 함수와 목록에서 항목을 가져오는 data() 함수만 구현하면 됩니다.

이 모델은 1차원 구조를 나타내므로, rowCount() 함수는 모델에 포함된 항목의 총 개수를 반환합니다. columnCount() 함수는 모든 종류의 뷰와의 상호 운용성을 위해 구현되었지만, 기본적으로 뷰에 모델이 단일 열만 포함하고 있음을 알립니다.

서브클래스 생성

QAbstractListModel을 상속할 때는 rowCount() 및 data() 함수의 구현을 제공해야 합니다. 올바르게 동작하는 모델은 headerData() 구현도 제공합니다.

모델이 QML 내에서 사용되며 roleNames() 함수가 제공하는 기본 역할 이외의 역할이 필요한 경우, 이 함수를 재정의해야 합니다.

편집 가능한 목록 모델의 경우, setData()의 구현도 제공해야 하며, flags() 함수를 구현하여 Qt::ItemIsEditable 를 포함하는 값을 반환하도록 해야 합니다.

QAbstractListModel은 이 모델에 항목이 단 하나의 열로만 구성되어 있음을 뷰에 알리는 columnCount()의 기본 구현을 제공한다는 점에 유의하십시오.

크기 조정이 가능한 목록형 데이터 구조에 대한 인터페이스를 제공하는 모델은 insertRows() 및 removeRows()의 구현을 제공할 수 있습니다. 이러한 함수를 구현할 때는 연결된 모든 뷰가 변경 사항을 인식할 수 있도록 적절한 함수를 호출하는 것이 중요합니다:

참고: 모델의 서브클래스 생성에 대한 일반적인지침은 ‘모델 서브클래스 참조(Model Subclassing Reference)’에서 확인할 수 있습니다.

또한 ‘모델 클래스’, ‘모델 서브클래스 참조’, ‘ QAbstractItemView ’, ‘ QAbstractTableModel ’ 및 ‘ QRangeModel ’을 참조하십시오 .

멤버 함수 문서

[explicit] QAbstractListModel::QAbstractListModel(QObject *parent = nullptr)

주어진 ` parent`를 사용하여 추상 리스트 모델을 생성합니다.

[virtual noexcept] QAbstractListModel::~QAbstractListModel()

추상 리스트 모델을 파괴합니다.

[override virtual] bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)

QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)를 재구현합니다.

[override virtual] Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const

QAbstractItemModel::flags(const QModelIndex &index) const를 재구현합니다.

[override virtual] QModelIndex QAbstractListModel::index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const

다음 함수를 재구현합니다: QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.

parent 를 사용하여 row 및 column 내 데이터의 인덱스를 반환합니다.

parent()도 참조하십시오 .

[override virtual] QModelIndex QAbstractListModel::sibling(int row, int column, const QModelIndex &idx) const

QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const를 재구현합니다.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.