111 model->setTable(
"employee");
126 model.setTable(
"employee");
138 db.setHostName(
"bigblue");
139 db.setDatabaseName(
"flightdb");
140 db.setUserName(
"acarlson");
141 db.setPassword(
"1uTbSbAs");
168 query.exec(
"SELECT name, salary FROM employee WHERE salary > 50000");
172 while (
query.next()) {
185 query.exec(
"SELECT name, salary FROM employee WHERE salary > 50000");
189 numRows =
query.size();
193 numRows =
query.at() + 1;
202 query.exec(
"INSERT INTO employee (id, name, salary) "
203 "VALUES (1001, 'Thad Beaumont', 65000)");
211 query.prepare(
"INSERT INTO employee (id, name, salary) "
212 "VALUES (:id, :name, :salary)");
213 query.bindValue(
":id", 1001);
214 query.bindValue(
":name",
"Thad Beaumont");
215 query.bindValue(
":salary", 65000);
224 query.prepare(
"INSERT INTO employee (id, name, salary) "
226 query.addBindValue(1001);
227 query.addBindValue(
"Thad Beaumont");
228 query.addBindValue(65000);
237 query.exec(
"UPDATE employee SET salary = 70000 WHERE id = 1003");
245 query.exec(
"DELETE FROM employee WHERE id = 1007");
254 query.exec(
"SELECT id FROM employee WHERE name = 'Torild Halvorsen'");
256 int employeeId =
query.value(0).toInt();
257 query.exec(
"INSERT INTO project (id, name, ownerid) "
258 "VALUES (201, 'Manhattan Project', "
283 model.setTable(
"employee");
284 model.setFilter(
"salary > 50000");
299 model.setTable(
"employee");
347 bool isNull(
int )
override {
return false; }
349 bool fetch(
int )
override {
return false; }
352 int size()
override {
return 0; }
368 int ,
const QString & )
override
375 int main(
int argc,
char **argv)
small capitals from c petite p scientific i
[1]
[Quoting ModelView Tutorial]
QVariant data(const QModelIndex &item, int role) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
[Quoting ModelView Tutorial]
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
void setEditTriggers(EditTriggers triggers)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
The QCoreApplication class provides an event loop for Qt applications without UI.
The QModelIndex class is used to locate data in a data model.
The QSqlDatabase class handles a connection to a database.
QSqlDriver * driver() const
static QSqlDatabase database(const QString &connectionName=QLatin1String(defaultConnection), bool open=true)
static QSqlDatabase addDatabase(const QString &type, const QString &connectionName=QLatin1String(defaultConnection))
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
virtual bool hasFeature(DriverFeature f) const =0
The QSqlQuery class provides a means of executing and manipulating SQL statements.
The QSqlQueryModel class provides a read-only data model for SQL result sets.
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setQuery(QSqlQuery &&query)
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QSqlRecord record(int row) const
The QSqlRecord class encapsulates a database record.
QVariant value(int i) const
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases.
const QSqlDriver * driver() const
The QSqlTableModel class provides an editable data model for a single database table.
The QString class provides a Unicode character string.
static QString number(int, int base=10)
The QTableView class provides a default model/view implementation of a table view.
void setModel(QAbstractItemModel *model) override
void hideColumn(int column)
The QVariant class acts like a union for the most common Qt data types.
int toInt(bool *ok=nullptr) const
QSqlResult * createResult() const override
bool open(const QString &, const QString &, const QString &, const QString &, int, const QString &) override
bool hasFeature(DriverFeature) const override
int numRowsAffected() override
QVariant data(int) override
bool fetchLast() override
bool fetchFirst() override
bool reset(const QString &) override
QSqlRecord record() const override
XyzResult(const QSqlDriver *driver)
bool isNull(int) override
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
void QSqlField_snippets()
void QSqlDatabase_snippets()
void QSqlQueryModel_snippets()
void QSqlQuery_snippets()
int main(int argc, char **argv)
[48]
void sql_intro_snippets()
QSqlQueryModel * model
[16]
void QSqlTableModel_snippets()
[23]
QApplication app(argc, argv)
[0]