本文整理汇总了C++中QSqlTableModel::setTable方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::setTable方法的具体用法?C++ QSqlTableModel::setTable怎么用?C++ QSqlTableModel::setTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::setTable方法的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: setData
void simplePerson::setData(QString idx, QString tableName)
{
QSqlTableModel model;
model.setTable(tableName);
model.setFilter(QString("id = %1").arg(idx));
model.select();
id = model.data(model.index(0,0)).toString();
surname = model.data(model.index(0,1)).toString();
name = model.data(model.index(0,2)).toString();
patronimic = model.data(model.index(0,3)).toString();;
}
示例3: primaryKeyFieldName
QString TableSchema::primaryKeyFieldName() const
{
QSqlTableModel model;
model.setTable(tablename);
QSqlIndex index = model.primaryKey();
if (index.isEmpty()) {
return QString();
}
QSqlField fi = index.field(0);
return fi.name();
}
示例4: onDatabaseItemActivated
void DataViewer::onDatabaseItemActivated(const DatabaseItem &item)
{
if ((DatabaseItem::Table != item.m_type) &&
(DatabaseItem::View != item.m_type))
{
return;
}
d_ptr->database = item.m_database;
// for table tableShema
QSqlRecord record = item.m_database.record(item.m_value);
d_ptr->m_shemaModel->removeRows(0, d_ptr->m_shemaModel->rowCount());
d_ptr->m_shemaModel->insertRows(0, record.count());
for (int i = 0; i < record.count(); ++i)
{
QSqlField field = record.field(i);
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 0), field.name());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 1),
field.type() == QVariant::Invalid ? "???" : QString(QVariant::typeToName(field.type())));
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 2),
(field.length() < 0) ? QVariant("???") : field.length());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 3),
(field.precision() < 0) ? QVariant("???") : field.precision());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 4),
field.requiredStatus() == QSqlField::Unknown ? "???" : QVariant(bool(field.requiredStatus())));
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 5), field.isAutoValue());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 6), field.defaultValue());
}
d_ptr->m_tableShema->setModel(d_ptr->m_shemaModel.data());
d_ptr->m_tableShema->setEditTriggers(QAbstractItemView::NoEditTriggers);
d_ptr->m_tableShema->resizeColumnsToContents();
d_ptr->m_tab->setTabText(::Scheme, tr(::c_schemeTable).arg(item.m_value));
// for table tableData
QSqlTableModel *modelData = new QSqlTableModel(0, item.m_database);
modelData->setEditStrategy(QSqlTableModel::OnRowChange);
modelData->setTable(item.m_value);
modelData->select();
d_ptr->m_tableData->setModel(modelData);
d_ptr->m_tableData->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
d_ptr->m_tableData->resizeColumnsToContents();
d_ptr->m_tab->setTabText(::Data, tr(::c_dataTable).arg(item.m_value));
d_ptr->m_sqlDataModel.reset(modelData);
}
示例5: QDialog
SelectSysSwitchDlg::SelectSysSwitchDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::SelectSysSwitchDlg)
{
ui->setupUi(this);
QSqlTableModel *modelTable = new QSqlTableModel(this);
modelTable->setTable("tableSysSwitchCard");
modelTable->select();
ui->tableView->setModel(modelTable);
}
示例6: on_pbAggiungiPermesso_clicked
void FormGestioneFerie::on_pbAggiungiPermesso_clicked()
{
for(QDate a=ui->dePermessiDal->date(); a.operator <=( ui->dePermessiAl->date());a= a.addDays(1) )
{
qDebug() << "Permesso per "+ui->cbMatricola->currentText()+" per il giorno "+a.toString("dd/MM/yyyy");
QSqlQuery query;
query.prepare("INSERT INTO assenze (ID, matricola, causa, data)" "VALUES (?, ?, ?, ?)");
// query.addBindValue( ui->cbMatricola->currentText()+"_"+ui->dePermessiDal->date().toString("dd/MM/yyyy"));
query.addBindValue( ui->cbMatricola->currentText()+"_"+a.toString("dd/MM/yyyy"));
query.addBindValue( ui->cbMatricola->currentText());
query.addBindValue( ui->cbTipoPermesso->currentText());
// query.addBindValue( ui->dePermessiDal->date().toString("dd/MM/yyyy"));
query.addBindValue( a.toString("dd/MM/yyyy"));
if(query.exec())
{
QMessageBox msgBox;
msgBox.setText("Inserzione nel database.");
msgBox.setInformativeText(QString("Permesso per il giorno %1 inserito correttamente.").arg(a.toString("dd/MM/yyyy")));
msgBox.setStandardButtons(QMessageBox::Ok );
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
}
else
{
QMessageBox msgBox;
msgBox.setText("Inserzione nel database.");
msgBox.setInformativeText(QString("Permesso per il giorno %1 NON inserito nel database. Probabilmente è gia stato inserito un permesso per lo stesso giorno.").arg(a.toString("dd/MM/yyyy")));
msgBox.setStandardButtons(QMessageBox::Ok );
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
}
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);
}
}
示例7: primaryKeyIndex
int TableSchema::primaryKeyIndex() const
{
QSqlTableModel model;
model.setTable(tablename);
QSqlIndex index = model.primaryKey();
if (index.isEmpty()) {
return -1;
}
QSqlField fi = index.field(0);
return model.record().indexOf(fi.name());
}
示例8: afficherDoss
void Form::afficherDoss()
{
QSqlTableModel *model = new QSqlTableModel ();
model->setTable("info");
model->select();
ui->treeView->setModel( model );
ui->treeView->setColumnHidden(0,true);
ui->treeView->show();
}
示例9: select
QSqlTableModel* Dbconnect::select(QString table,QString filter)
{
qDebug("selectDataSQL");
QSqlTableModel *model = new QSqlTableModel;
QString tbName = Db::tbPrefix;
model->setTable(tbName.append(table));
if("" != filter){
model->setFilter(filter);
}
model->select();
qDebug("-------%d",model->rowCount());
return model;
}
示例10: 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
}
示例11: setUpdate
void partner::setUpdate(QString idt)
{
QSqlTableModel model;
model.setTable("Partner");
model.setFilter(QString("id = %1").arg(idt));
model.select();
id = model.data(model.index(0,0)).toInt();
ui->nameEdit->setText(model.data(model.index(0,1)).toString());
ui->surnameEdit->setText(model.data(model.index(0,2)).toString());
ui->patronimicEdit->setText(model.data(model.index(0,3)).toString());
ui->passportEdit->setText(model.data(model.index(0,4)).toString());
ui->phoneEdit->setText(model.data(model.index(0,5)).toString());
mode = updateMode;
}
示例12: loadLayout
void FormPerson::loadLayout(QString tableName)
{
// Recupero link al database
QSqlDatabase db = QSqlDatabase::database("ConnectionToDB");
// Creo un modello sche si riferirà alla tabella delle mail
QSqlTableModel *model = new QSqlTableModel(this, db);
// Imposto la tabella a cui si riferirà il modello
model->setTable(tableName);
// Imposto un filtro sulla persona a cui la tabella è collegata
model->setFilter("id_person=" + QString::number(this->personId));
model->select();
// Per ciascuna riga della tabella...
for (int i=0; i<model->rowCount(); i++)
{
QHBoxLayout *hbl = new QHBoxLayout();
// Creo un nuovo oggetto QLineEdit
QLineEdit *qlineedit = new QLineEdit();
// Creo un pulsante per la successiva rimozione dell'entry nel database
RemoveRowFromModel *button = new RemoveRowFromModel(i, model, tableName);
// Collego il pulante alla funzione di refresh
QObject::connect(button, SIGNAL(rowRemoved(QString)), this, SLOT(refreshLayout(QString)));
// Creo un mapper
QDataWidgetMapper *mapperEmailPerson = new QDataWidgetMapper();
// Collego al mapper il modello della tabella
mapperEmailPerson->setModel(model);
// Aggiungo un mapping tra l'oggetto QLineEdit e il modello
mapperEmailPerson->addMapping(qlineedit, 1);
// Posiziono il mapper sull'indice opportuno
mapperEmailPerson->setCurrentIndex(i);
// Inserisco il mapper nella lista dei mapper per le email
getQDataWidgetMapperList(tableName)->append(mapperEmailPerson);
// qlineedit e button, li visualizzo sulla stessa riga (li inserisco in un layout orizzontale)
hbl->addWidget(qlineedit);
hbl->addWidget(button);
// Inserisco il layout orizzontale nel layout delle mail
getVerticalLayout(tableName)->addLayout(hbl);
// Collego il pulsante ad uno slot, in modo che venga gestita la rimozione di una riga dal
// modello
}
}
示例13: printNeighbor
void Control::printNeighbor()
{
QString whichID = ui->comboBox_5->currentText();
QSqlTableModel* model = new QSqlTableModel(this);
model->setTable("Distance");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setFilter("CellID1="+whichID+" and distance<=2 order by distance asc");
model->setHeaderData(1,Qt::Horizontal,tr("邻居"));
model->setHeaderData(2,Qt::Horizontal,tr("距离(千米)"));
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
ui->tableView->setColumnHidden(model->fieldIndex("CellID1"),true);
}
示例14: 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]
}
}
示例15: showTable
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();
}