本文整理汇总了C++中QSqlTableModel::database方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::database方法的具体用法?C++ QSqlTableModel::database怎么用?C++ QSqlTableModel::database使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::database方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: submitChangement
void FenPrincipale::submitChangement()
{
QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tabless->model());
model->database().transaction();
if (model->submitAll()) {
model->database().commit();
} else {
model->database().rollback();
QMessageBox::warning(this, tr("Cached Table"),
tr("The database reported an error: %1")
.arg(model->lastError().text()));
}
}
示例2: tablename
TableSchema::TableSchema(const QString &table, const QString &env)
: tablename(table)
{
if (!dbSettings) {
QString path = QLatin1String("config") + QDir::separator() + "database.ini";
if (!QFile::exists(path)) {
qCritical("not found, %s", qPrintable(path));
}
dbSettings = new QSettings(path, QSettings::IniFormat);
}
if (openDatabase(env)) {
if (!tablename.isEmpty()) {
QSqlTableModel model;
model.setTable(tablename);
tableFields = model.record();
if (model.database().driverName().toUpper() == "QPSQL") {
// QPSQLResult doesn't call QSqlField::setAutoValue(), fix it
for (int i = 0; i < tableFields.count(); ++i) {
QSqlField f = tableFields.field(i);
if (f.defaultValue().toString().startsWith(QLatin1String("nextval"))) {
f.setAutoValue(true);
tableFields.replace(i, f);
}
}
}
} else {
qCritical("Empty table name");
}
}
}
示例3: addClicked
void QgsBookmarks::addClicked()
{
QSqlTableModel *model = qobject_cast<QSqlTableModel *>( lstBookmarks->model() );
Q_ASSERT( model );
QgsMapCanvas *canvas = QgisApp::instance()->mapCanvas();
Q_ASSERT( canvas );
QSqlQuery query( "INSERT INTO tbl_bookmarks(bookmark_id,name,project_name,xmin,ymin,xmax,ymax,projection_srid)"
" VALUES (NULL,:name,:project_name,:xmin,:xmax,:ymin,:ymax,:projection_srid)",
model->database() );
QString projStr( "" );
if ( QgsProject::instance() )
{
if ( !QgsProject::instance()->title().isEmpty() )
{
projStr = QgsProject::instance()->title();
}
else if ( !QgsProject::instance()->fileName().isEmpty() )
{
QFileInfo fi( QgsProject::instance()->fileName() );
projStr = fi.exists() ? fi.fileName() : "";
}
}
query.bindValue( ":name", tr( "New bookmark" ) );
query.bindValue( ":project_name", projStr );
query.bindValue( ":xmin", canvas->extent().xMinimum() );
query.bindValue( ":ymin", canvas->extent().yMinimum() );
query.bindValue( ":xmax", canvas->extent().xMaximum() );
query.bindValue( ":ymax", canvas->extent().yMaximum() );
query.bindValue( ":projection_srid", QVariant::fromValue( canvas->mapSettings().destinationCrs().srsid() ) );
if ( query.exec() )
{
model->setSort( 0, Qt::AscendingOrder );
model->select();
lstBookmarks->scrollToBottom();
lstBookmarks->setCurrentIndex( model->index( model->rowCount() - 1, 1 ) );
lstBookmarks->edit( model->index( model->rowCount() - 1, 1 ) );
}
else
{
QMessageBox::warning( this, tr( "Error" ), tr( "Unable to create the bookmark.\nDriver:%1\nDatabase:%2" )
.arg( query.lastError().driverText() )
.arg( query.lastError().databaseText() ) );
}
}