QAbstractTableModel Class
QAbstractTableModel 클래스는 테이블 모델을 생성하기 위해 하위 클래스로 확장할 수 있는 추상 모델을 제공합니다. 더 보기...
| 헤더: | #include <QAbstractTableModel> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 상속: | QAbstractItemModel |
| 상속받는 클래스: |
공개 함수
| QAbstractTableModel(QObject *parent = nullptr) | |
| virtual | ~QAbstractTableModel() |
재구현된 공용 함수
| 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, const QModelIndex &parent = QModelIndex()) const override |
| virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
상세 설명
QAbstractTableModel은 데이터를 항목을 포함한 2차원 배열로 표현하는 모델에 대한 표준 인터페이스를 제공합니다. 이 클래스는 직접 사용되지 않으며, 반드시 하위 클래스를 상속받아 구현해야 합니다.
이 모델은 ` QAbstractItemModel`보다 더 특화된 인터페이스를 제공하므로, ` QListView`에 데이터를 제공하는 데는 사용할 수 있지만 트리 뷰와 함께 사용하기에는 적합하지 않습니다. 간단한 항목 목록을 표현해야 하고, 모델이 단일 열의 데이터만 포함하면 되는 경우에는 ` QAbstractListModel `을 상속하는 것이 더 적절할 수 있습니다.
rowCount() 및 columnCount() 함수는 테이블의 차원을 반환합니다. 모델 내의 특정 항목에 해당하는 모델 인덱스를 가져오려면 index()를 사용하고 행 번호와 열 번호만 지정하십시오.
서브클래스 생성
QAbstractTableModel을 상속할 때는 rowCount(), columnCount() 및 data()을 구현해야 합니다. index() 및 parent() 함수의 기본 구현은 QAbstractTableModel에서 제공됩니다. 올바르게 동작하는 모델은 headerData()도 구현해야 합니다.
편집 가능한 모델은 setData()을 구현해야 하며, Qt::ItemIsEditable 을 포함하는 값을 반환하기 위해 flags()을 구현해야 합니다.
크기 조정이 가능한 데이터 구조에 대한 인터페이스를 제공하는 모델은 insertRows(), removeRows(), insertColumns() 및 removeColumns()의 구현을 제공할 수 있습니다. 이러한 함수를 구현할 때는 연결된 모든 뷰가 변경 사항을 인식할 수 있도록 적절한 함수를 호출하는 것이 중요합니다:
- insertRows() 구현은 데이터 구조에 새 행을 삽입하기 전에 beginInsertRows()을 호출해야 하며, 삽입이 완료된 직후 endInsertRows()을 호출해야 합니다.
- insertColumns() 구현은 데이터 구조에 새 열을 삽입하기 전에 beginInsertColumns()를 호출해야 하며, 삽입 직후 endInsertColumns()를 호출해야 합니다.
- removeRows() 구현은 데이터 구조에서 행을 제거하기 전에 beginRemoveRows()를 호출해야 하며, 그 직후에 endRemoveRows()를 호출해야 합니다.
- removeColumns() 구현체는 열이 데이터 구조에서 제거되기 전에 beginRemoveColumns()를 호출해야 하며, 그 직후에 endRemoveColumns()를 호출해야 합니다.
참고: 모델 서브클래스 생성에 대한 일반적인지침은 ‘모델 서브클래스 참조’에서 확인할 수 있습니다.
스레드 안전성
QObject의 서브클래스인 QAbstractTableModel은 스레드 안전( thread-safe)하지 않습니다. QAbstractTableModel 모델 관련 API는 모델 객체가 존재하는 스레드에서만 호출해야 합니다. QAbstractTableModel이 뷰에 연결된 경우, 뷰가 GUI 스레드에 상주하며 해당 스레드에서 모델과 상호 작용하므로 모델도 GUI 스레드에서 작동합니다. 백그라운드 스레드를 사용하여 모델의 내용을 채우거나 수정할 수는 있지만, 모델 관련 API를 직접 호출할 수 없으므로 주의해서 처리해야 합니다. 대신, 업데이트를 큐에 넣은 후 메인 스레드에서 적용해야 합니다. 이는 큐 기반 연결을 통해 수행할 수 있습니다.
관련 항목: 모델 클래스, QAbstractItemModel, QAbstractListModel, QRangeModel.
멤버 함수 문서
[explicit] QAbstractTableModel::QAbstractTableModel(QObject *parent = nullptr)
주어진 parent 에 대한 추상 테이블 모델을 생성합니다.
[virtual noexcept] QAbstractTableModel::~QAbstractTableModel()
추상 테이블 모델을 삭제합니다.
[override virtual] bool QAbstractTableModel::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 QAbstractTableModel::flags(const QModelIndex &index) const
QAbstractItemModel::flags(const QModelIndex &index) const를 재구현합니다.
[override virtual] QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
다음 함수를 재구현합니다: QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.
parent 를 사용하여 row 및 column 내 데이터의 인덱스를 반환합니다.
parent()도 참조하십시오 .
[override virtual] QModelIndex QAbstractTableModel::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.