Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsqlquerymodel.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSQLQUERYMODEL_H
5#define QSQLQUERYMODEL_H
6
7#include <QtSql/qtsqlglobal.h>
8#include <QtCore/qabstractitemmodel.h>
9#include <QtSql/qsqldatabase.h>
10
12
14
16class QSqlError;
17class QSqlRecord;
18class QSqlQuery;
19
20class Q_SQL_EXPORT QSqlQueryModel: public QAbstractTableModel
21{
23 Q_DECLARE_PRIVATE(QSqlQueryModel)
24
25public:
26 explicit QSqlQueryModel(QObject *parent = nullptr);
27 virtual ~QSqlQueryModel();
28
29 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
30 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
31 QSqlRecord record(int row) const;
32 QSqlRecord record() const;
33
34 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
35 QVariant headerData(int section, Qt::Orientation orientation,
36 int role = Qt::DisplayRole) const override;
37 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
38 int role = Qt::EditRole) override;
39
40 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
41 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
42
43#if QT_DEPRECATED_SINCE(6, 2)
44 QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Pass it by move instead.")
45 void setQuery(const QSqlQuery &query);
46#endif
47 void setQuery(QSqlQuery &&query);
48 void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase());
49#if QT_SQL_REMOVED_SINCE(6, 5)
50 QSqlQuery query() const;
51#endif
53
54 virtual void clear();
55
56 QSqlError lastError() const;
57
58 void fetchMore(const QModelIndex &parent = QModelIndex()) override;
59 bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override;
60
61 QHash<int, QByteArray> roleNames() const override;
62
63protected:
64 void beginInsertRows(const QModelIndex &parent, int first, int last);
65 void endInsertRows();
66
67 void beginRemoveRows(const QModelIndex &parent, int first, int last);
68 void endRemoveRows();
69
70 void beginInsertColumns(const QModelIndex &parent, int first, int last);
71 void endInsertColumns();
72
73 void beginRemoveColumns(const QModelIndex &parent, int first, int last);
74 void endRemoveColumns();
75
76 void beginResetModel();
77 void endResetModel();
78 virtual void queryChange();
79
80 virtual QModelIndex indexInQuery(const QModelIndex &item) const;
81 void setLastError(const QSqlError &error);
83};
84
86
87#endif // QSQLQUERYMODEL_H
void endResetModel()
Completes a model reset operation.
virtual Q_INVOKABLE QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
void endRemoveRows()
Ends a row removal operation.
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
Begins a column removal operation.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual Q_INVOKABLE void fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
virtual Q_INVOKABLE bool canFetchMore(const QModelIndex &parent) const
Returns {true} if there is more data available for parent; otherwise returns {false}.
virtual QHash< int, QByteArray > roleNames() const
void beginInsertColumns(const QModelIndex &parent, int first, int last)
Begins a column insertion operation.
void endInsertRows()
Ends a row insertion operation.
void beginResetModel()
Begins a model reset operation.
void endRemoveColumns()
Ends a column removal operation.
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
void endInsertColumns()
Ends a column insertion operation.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Sets the data for the given role and section in the header with the specified orientation to the valu...
\inmodule QtCore
Definition qhash.h:818
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:90
The QSqlDatabase class handles a connection to a database.
The QSqlError class provides SQL database error information.
Definition qsqlerror.h:17
The QSqlQueryModel class provides a read-only data model for SQL result sets.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition qsqlquery.h:23
The QSqlRecord class encapsulates a database record.
Definition qsqlrecord.h:20
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
b clear()
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:97
@ EditRole
@ DisplayRole
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint first
GLenum GLenum GLsizei void GLsizei void * column
GLenum query
GLenum GLenum GLsizei void * row
#define QT_REQUIRE_CONFIG(feature)
#define QT_DEPRECATED_VERSION_X_6_2(text)
#define Q_OBJECT
#define QT6_DECL_NEW_OVERLOAD
qDebug()<< QUrl("file copy setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode)
QMimeDatabase db
[0]
MyRecord record(int row) const
[0]
QGraphicsItem * item
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent