本文整理汇总了C++中QSqlTableModel::submitAll方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::submitAll方法的具体用法?C++ QSqlTableModel::submitAll怎么用?C++ QSqlTableModel::submitAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::submitAll方法的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: saveUnits
void Database::saveUnits(QString userName, QList<Unit> units)
{
QSqlTableModel model;
model.setTable("user");
model.select();
QString saveName;
for (int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
if (record.value("name").toString()==userName)
{
saveName=record.value("id").toString();
break;
}
}
saveName.prepend("save");
model.setTable(saveName);
int row=0, line=0;
model.select();
model.removeRows(row, model.rowCount());
model.submitAll();
while(line<units.size())
{
model.insertRows(row,1);
model.setData(model.index(row,0), line+1);
model.setData(model.index(row,1), units[line].imageFileName);
model.setData(model.index(row,2), units[line].faceLeft);
model.setData(model.index(row,3), units[line].vLocation);
model.setData(model.index(row,4), units[line].hLocation);
model.setData(model.index(row,5), units[line].hitPoints);
model.setData(model.index(row,6), units[line].totalHitPoints);
model.setData(model.index(row,7), units[line].actionTime);
model.setData(model.index(row,8), units[line].actionRate);
model.setData(model.index(row,9), units[line].movementRange);
model.setData(model.index(row,10), units[line].attackRange);
model.setData(model.index(row,11), units[line].attackPower);
model.setData(model.index(row,12), units[line].status);
model.setData(model.index(row,13), units[line].maskFileName);
model.setData(model.index(row,14), units[line].team);
model.setData(model.index(row,15), units[line].unitWorth);
model.submitAll();
line++;
}
}
示例3: writeCensus
bool DatabaseHandler::writeCensus(census * obj) {
qDebug() << "Writing object data to database.";
QSqlTableModel table;
table.setTable("census");
table.setFilter("rcns_id=" + QString::number(obj->id) + " AND usr='" + obj->usr + "'");
table.select();
// get record structure from db
QSqlRecord record(table.record());
// initialize record with census-structure values
setRecordTable(&record, obj);
// insert or update records in db
if (table.rowCount() == 0) { //INSERT
qDebug() << "Insert!";
// remove first entry of record
// auto increment of id is handled by postgres
record.remove(0);
bool done = table.insertRecord(-1,record);
qDebug() << table.lastError();
return done;
} else { //UPDATE
qDebug() << "Update!";
record.setValue("fcns_id",table.record(0).value(0).toInt());
bool check = true;
check = check && table.setRecord(0, record);
check = check && table.submitAll();
qDebug() << table.lastError();
return check;
}
return true;
}
示例4: saveTemplateChapter
void MaterialSaverDB::saveTemplateChapter( StockMaterial* tmpl )
{
if( ! tmpl ) {
kDebug() << "Parameter error, zero material!";
return;
}
dbID id = tmpl->getID();
dbID chapId = tmpl->chapterId();
QSqlTableModel model;
model.setTable("stockMaterial");
QString templID = id.toString();
model.setFilter( "matID=" + templID );
model.select();
QSqlRecord buffer = model.record();
if( model.rowCount() > 0)
{
kDebug() << "Updating material chapter " << templID << endl;
buffer = model.record(0);
buffer.setValue( "chapterID", chapId.toString() );
model.setRecord(0, buffer);
model.submitAll();
} else {
kDebug() << "Could not update material chapter, not found with id " << templID;
}
}
示例5: saveTemplate
bool MaterialSaverDB::saveTemplate( StockMaterial *mat )
{
bool res = true;
// Transaktion ?
QSqlTableModel model;
model.setTable("stockMaterial");
QString templID = QString::number( mat->getID() );
model.setFilter( "matID=" + templID );
model.select();
QSqlRecord buffer = model.record();
if( model.rowCount() > 0)
{
kDebug() << "Updating material " << mat->getID() << endl;
// mach update
buffer = model.record(0);
fillMaterialBuffer( buffer, mat, false );
model.setRecord(0, buffer);
model.submitAll();
}
else
{
// insert
kDebug() << "Creating new material database entry" << endl;
fillMaterialBuffer( buffer, mat, true );
model.insertRecord(-1, buffer);
model.submitAll();
/* Jetzt die neue Template-ID selecten */
dbID id = KraftDB::self()->getLastInsertID();
kDebug() << "New Database ID=" << id.toInt() << endl;
if( id.isOk() ) {
mat->setID( id.toInt() );
templID = id.toString();
} else {
kDebug() << "ERROR: Kann AUTOINC nicht ermitteln" << endl;
res = false;
}
}
return res;
}
示例6: importData
void MainWindow::importData()
{
int exam_id;
QString dataFileName = QFileDialog::getOpenFileName(this,tr("Import Data From a CSV File"),QDir::homePath(),tr("CSV File (*.csv)"));
if(dataFileName.isEmpty())
return;
QFile dataFile(dataFileName);
if(!dataFile.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this,tr("Open File Failed"),tr("Cannot open selected file"));;
return;
}
QSqlTableModel* student = m_scoreView->studentListModel();
QSqlTableModel* exam = m_scoreView->examListModel();
QSqlRelationalTableModel* score = m_scoreView->scoreListModel();
QFileInfo tmp(dataFileName);
QString exam_name = tmp.baseName();
exam->setFilter(QString("name = \'%1\'").arg(exam_name));
if(exam->rowCount() == 1)
{
QSqlRecord rq = exam->record(0);
exam_id = rq.value("id").toInt();
}
else
{
exam->insertRow(0);
exam->setData(exam->index(0,Global::Exam_Name),exam_name);
exam->submitAll();
exam->setFilter(QString("name = \'%1\'").arg(exam_name));
QSqlRecord rq = exam->record(0);
exam_id = rq.value("id").toInt();
}
QHash<QString,int> studentMap;
for(int row = 0;row < student->rowCount();++row)
studentMap.insert(student->data(student->index(row,1)).toString(),student->data(student->index(row,0)).toInt());
QTextStream in(&dataFile);
QString record = in.readLine();
QStringList candidate_seps;
candidate_seps << ";" << "," << "\t" << " ";
QString real_sep;
bool is_legal = false;
QStringList cols;
foreach(real_sep, candidate_seps)
{
cols = record.split(real_sep);
if(cols.size() == 11)
{
is_legal = true;
break;
}
}
示例7: qDebug
void ChengjiaoQianyueDialog::on_pushButton_3_clicked(){
qDebug() << "add";
QSqlTableModel * model = this->dbcon->qianyue;
int row = this->tableViewqianyue->currentIndex().row();
model->setData(model->index(row, 0), this->comboBoxFang->currentText());
model->setData(model->index(row, 1), this->comboBoxKe->currentText());
model->setData(model->index(row, 2), this->comboBoxRen->currentText());
model->setData(model->index(row, 3), this->spinBoxYongjin->text().toInt());
model->setData(model->index(row, 4), this->comboBoxFen->currentText());
model->setData(model->index(row, 5), this->spinBoxBianhao->text().toInt());
model->submitAll();
}
示例8: tr
//插入一条记录
void
Widget::CStudentDialog::insertRecord()
{
bool ok;
QString name = m_pNameEdit->text();
QString Sex = m_pSexEdit->text();
double age = m_pAgeEdit->text().toDouble( &ok );
if( !ok ){
QMessageBox::warning( this , "错误" , "请重新填写年龄" );
return;
}
QString number = m_pNumberEdit->text();
QString post = m_pPostEdit->text();
QSqlTableModel table;
table.setTable( "person" );
table.select();
QSqlRecord record;
record = table.record();
record.setValue( "name" , name );
record.setValue( "gender" , Sex );
record.setValue( "age" , age );
ok = table.insertRecord( -1, record );
if( !ok ){
AddStudentError
}
table.submitAll();
table.setTable( "person" );
table.setFilter( tr("name = '%0'").arg( name ) );
qDebug() << table.select();
int id = table.record(0).value( Enum::PersonSection::Person_id ).toInt( &ok );
if( !ok ){
table.removeRow( 0 );
table.submitAll();
AddStudentError
}
示例9: changeVoteMark
void MainWindow::changeVoteMark() {
if(ui->articleList->currentIndex().isValid()) {
int res = changeMarkDlg->exec();
if(res == QDialog::Accepted) {
QSqlTableModel* mdl = mysqlDataModel->getMapTableModel();
int rowIndex = ui->articleList->currentIndex().row();
mdl->setData(mdl->index(rowIndex, 3), QString::fromStdString(TriangleNumber::getBindedStrID(changeMarkDlg->getVoteMark())));
mdl->submitAll();
mdl->select();
}
}
}
示例10: 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()));
}
}
示例11: 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;
}
}
}
示例12: deleteRow
void FenPrincipale::deleteRow()
{
QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tablemesures->model());
if (!model)
return;
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
QModelIndexList currentSelection = tablemesures->selectionModel()->selectedIndexes();
for (int i = 0; i < currentSelection.count(); ++i) {
if (currentSelection.at(i).column() != 0)
continue;
model->removeRow(currentSelection.at(i).row());
}
model->submitAll();
model->setEditStrategy(QSqlTableModel ::OnManualSubmit);
}
示例13: 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;
}
}
}
示例14: 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;
}
}
}
示例15: 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);
}