本文整理汇总了C++中QSqlTableModel类的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel类的具体用法?C++ QSqlTableModel怎么用?C++ QSqlTableModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlTableModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateRoom
//------------------Above Date--------------------------
void Liveinfo::UpdateRoom(int RoomNum,int change)
{
QSqlTableModel * updateroom = new QSqlTableModel; //修改已入住的房间
updateroom->setTable("Room");
updateroom->select();
for(int i = 0;i < updateroom->rowCount(); ++i)
{
QSqlRecord Roomrecord = updateroom->record(i);
int check_room = Roomrecord.value("Num").toInt();
if( check_room == RoomNum )
{
Roomrecord.setValue("Live",change);
updateroom->setRecord(i, Roomrecord);
}
}
updateroom->submitAll();
}
示例2: updateRules
void CDeleteAclTask::updateRules(int ruleId,int cmdType)
{
QSqlTableModel model;
model.setTable("aclrules");
QString filter1=QString("id=%1").arg(ruleId);
model.setFilter(filter1);
model.select();
if (model.rowCount()==1)
{
QSqlRecord record=model.record(0);
record.setValue("cmdtype",cmdType);
model.setRecord(0,record);
}
model.submitAll();
//QString error=model.lastError().text();
//QMessageBox::information(this, tr("information"), error);
}
示例3: while
CollectionTreeWidgetItem *CollectionTreeWidget::addMusic(Music *music, unsigned int id) {
// Find id in database if we don't have it
if (id == 0) {
QSqlTableModel *model = service->collectionModel();
// SQLite used two single quotes to escape a single quote! :)
QString filter = "artist = '" + music->getArtist().replace("'","''") + "' AND "
"album = '" + music->getAlbum().replace("'","''") + "' AND "
"music = '" + music->getTitle().replace("'","''") + "'";
model->setFilter(filter);
model->select();
while (model->canFetchMore()) model->fetchMore();
int total = model->rowCount();
if (total > 0) {
id = model->record(0).value(model->fieldIndex("id_music")).toInt();
}
else {
qDebug("ERROR: no songs found! -- " + model->filter().toUtf8());
return NULL;
}
}
// Looks for the album
QTreeWidgetItem *albumItem = addAlbum(music->getArtist(), music->getAlbum());
// Create our new music node and add it if it was not found
removeMusic(id);
CollectionTreeWidgetItem *newMusicNode = new CollectionTreeWidgetItem(LevelMusic, id, (QTreeWidget*)0);
newMusicNode->setText(0, music->getTitle());
newMusicNode->setIcon(0, IconFactory::fromTheme("sound"));
albumItem->addChild(newMusicNode);
musicList.append(newMusicNode);
return newMusicNode;
}
示例4: QSqlTableModel_snippets
void QSqlTableModel_snippets()
{
//! [24]
QSqlTableModel *model = new QSqlTableModel(parentObject, database);
model->setTable("employee");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
QTableView *view = new QTableView;
view->setModel(model);
view->hideColumn(0); // don't show the ID
view->show();
//! [24]
{
//! [25]
QSqlTableModel model;
model.setTable("employee");
QString name = model.record(4).value("name").toString();
//! [25]
}
}
示例5: query
void FormGestioneFerie::on_tvPermessi_doubleClicked(const QModelIndex &index)
{
if(index.column()==2)
{
QMessageBox msgBox;
msgBox.setText("Cancella assenza programmata.");
msgBox.setInformativeText(QString("Cancellare l'assenza programmata di %2 per il giorno %1 ?").arg(index.data().toString()).arg(ui->cbCognome->currentText()));
msgBox.setStandardButtons(QMessageBox::Apply |QMessageBox::Discard );
msgBox.setIcon(QMessageBox::Question);
int ret = msgBox.exec();
if (ret==QMessageBox::Apply )
{
QSqlQuery query(QString("DELETE FROM assenze where id=\"%1\"").arg(ui->cbMatricola->currentText()+"_"+index.data().toString()));
query.exec();
qDebug() << query.lastError();
QSqlTableModel *model = new QSqlTableModel(this, this->db);
model->setTable("assenze");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
model->sort(2,Qt::AscendingOrder);
model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
ui->tvPermessi->setModel(model);
ui->tvPermessi->hideColumn(0);
ui->tvPermessi->resizeColumnsToContents();
ui->tvPermessi->resizeRowsToContents();
ui->tvPermessi->selectRow(0);
}
}
}
示例6: 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()));
}
}
示例7: saveLevel
void Database::saveLevel(QString &userName, int level)
{
QSqlTableModel model;
model.setTable("user");
model.select();
for (int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
if (record.value("name").toString()==userName)
{
record.setValue("level", level);
model.setRecord(i, record);
model.submitAll();
break;
}
}
}
示例8: deactivateUser
void Database::deactivateUser(QString &userName)
{
QSqlTableModel model;
model.setTable("user");
model.select();
for (int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
if (record.value("name").toString()==userName)
{
record.setValue("isActive", false);
model.setRecord(i, record);
model.submitAll();
break;
}
}
}
示例9: saveXP
void Database::saveXP(QString &userName, int xp)
{
QSqlTableModel model;
model.setTable("user");
model.select();
for (int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
if (record.value("name").toString()==userName)
{
record.setValue("experiencePoints", xp);
model.setRecord(i, record);
model.submitAll();
break;
}
}
}
示例10: QSqlTableModel
void Browser::showTable(const QString &t)
{
QSqlTableModel *model = new QSqlTableModel(table, connectionWidget->currentDatabase());
model->setEditStrategy(QSqlTableModel::OnRowChange);
model->setTable(t);
model->select();
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
table->setModel(model);
table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(currentChanged()));
updateActions();
}
示例11: saveUser
void Database::saveUser(QString &userName, User user)
{
QSqlTableModel model;
model.setTable("user");
model.select();
for (int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
if (record.value("name").toString()==userName)
{
record.setValue("experiencePoints", user.experiencePoints);
record.setValue("isActive", user.isActive);
record.setValue("level", user.level);
model.setRecord(i, record);
model.submitAll();
break;
}
}
}
示例12: tr
bool ChangePassword::on_pushButton_clicked()
{
if (ui->new_2->text()!= ui->new_3->text())
{
QMessageBox::information(this, tr("警告!"),tr("两次输入的密码不一致,请重新输入!"));
ui->new_2->clear();
ui->new_3->clear();
return false;
}
root.open();
QSqlTableModel *user = new QSqlTableModel(this,root);
user->setTable("user");
user->setFilter(tr("user='%1' and password = '%2'").arg(username,ui->old->text()));
user->select();
if (user->rowCount() <= 0)
{
QMessageBox::information(this, tr("警告!"),tr("密码输入错误,请重新输入!"));
root.close();
return false;
}
else
{
user->setData(user->index(0,1),ui->new_2->text());
user->submitAll();
root.close();
QMessageBox::information(this, tr(" 修改成功!"),tr("密码修改成功!!"));
close();
return true;
}
root.close();
}
示例13: setModelData
void MySqlRelationDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!index.isValid())
return;
QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !childModel || !combo) {
if (HandbookDialog::m_record.fieldName(index.column()).contains("IS_", Qt::CaseSensitive))
{
QCheckBox * checkBox = qobject_cast<QCheckBox *>(editor);
sqlModel->setData(index, checkBox->isChecked(), Qt::DisplayRole);
sqlModel->setData(index, checkBox->isChecked(), Qt::EditRole);
return;
}
else if (HandbookDialog::m_record.fieldName(index.column()).contains("DATE_", Qt::CaseSensitive))
{
QDateEdit * dateEdit = qobject_cast<QDateEdit *>(editor);
sqlModel->setData(index, dateEdit->date().toString("yyyy-MM-dd"), Qt::DisplayRole);
sqlModel->setData(index, dateEdit->date().toString("yyyy-MM-dd"), Qt::EditRole);
return;
}
else
{
QItemDelegate::setModelData(editor, model, index);
return;
}
}
int currentItem = combo->currentIndex();
int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());
sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole),
Qt::DisplayRole);
sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole),
Qt::EditRole);
}
示例14: QSqlTableModel
void mainWindow::setupComboBox()
{
QSqlTableModel* m = new QSqlTableModel();
m->setTable("Consoles");
m->removeColumn(0);
m->select();
QStringList list;
for(int i = 0; i < m->rowCount(); i++)
{
list.append(m->record(i).value(0).toString());
}
list.removeDuplicates();
list.sort();
ui->comboConsole->clear();
ui->comboConsole->addItems(list);
}
示例15: QWidget
Widget::Widget(QString n, QString p, QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setFixedSize(470,230);
setWindowTitle("您的银行账户");
name = n;
pwd = p;
QSqlTableModel model;
model.setTable("bankaccount");
model.setFilter(tr("bankaccountnumber = '%1'").arg(name));
model.select();
QString bn = model.record(0).value("bankname").toString();
QString ln = model.record(0).value("lastname").toString();
QString fn = model.record(0).value("firstname").toString();
QString ban = model.record(0).value("bankaccountnumber").toString();
ui->bankname->setText(tr("%1").arg(bn));
ui->name->setText(tr("%1%2").arg(ln).arg(fn));
ui->bankan->setText(tr("%1").arg(ban));
}