本文整理汇总了C++中QSqlTableModel::data方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::data方法的具体用法?C++ QSqlTableModel::data怎么用?C++ QSqlTableModel::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::data方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setModelData
void mySqlRelationalDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!index.isValid())
return;
QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
QSortFilterProxyModel* proxyModel = NULL;
if (!sqlModel )
{
proxyModel = qobject_cast<QSortFilterProxyModel *>(model);
if (proxyModel)
sqlModel = qobject_cast<QSqlRelationalTableModel *>(proxyModel->sourceModel());
}
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !childModel || !combo) {
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());
if (proxyModel) {
proxyModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
proxyModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
} else {
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);
}
}
示例2: 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;
}
}
示例3: 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();;
}
示例4: QSqlQueryModel_snippets
void QSqlQueryModel_snippets()
{
{
//! [16]
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT name, salary FROM employee");
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
//! [17]
QTableView *view = new QTableView;
//! [17] //! [18]
view->setModel(model);
//! [18] //! [19]
view->show();
//! [16] //! [19] //! [20]
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
//! [20]
}
//! [21]
QSqlTableModel model;
model.setTable("employee");
model.select();
int salary = model.record(4).value("salary").toInt();
//! [21]
Q_UNUSED(salary);
{
//! [22]
int salary = model.data(model.index(4, 2)).toInt();
//! [22]
Q_UNUSED(salary);
}
for (int row = 0; row < model.rowCount(); ++row) {
for (int col = 0; col < model.columnCount(); ++col) {
qDebug() << model.data(model.index(row, col));
}
}
}
示例5: getrowoffacturation
int FacturationIO::getrowoffacturation(QSqlTableModel & modelfacturation,const QString & factureid)
{
int row = 0;
for ( int i = 0; i < modelfacturation.rowCount(); ++i)
{
if (modelfacturation.data(modelfacturation.index(i,ID_FACTURE),Qt::DisplayRole).toString() == factureid)
{
row = i;
}
}
return row;
}
示例6: 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);
}
示例7: on_currencyComboBox_currentIndexChanged
void MainWindow::on_currencyComboBox_currentIndexChanged(int index)
{
int row = ui->assetsTable->currentIndex().row();
QVariant current_value = model->data(model->index(row, currency_column_index), Qt::DisplayRole);
QSqlTableModel *childModel = model->relationModel(currency_column_index);
int childColIndex = childModel->fieldIndex("code");
QVariant new_value = childModel->data(childModel->index(index, childColIndex), Qt::DisplayRole);
if(current_value != new_value) {
mapper->submit();
}
}
示例8: 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;
}
示例9: on_pushBtnSel_clicked
void SelectLiftDlg::on_pushBtnSel_clicked()
{
int curRow = ui->tableView->currentIndex().row();
if(curRow<0)
{
QMessageBox::warning(this,"警告","请先选择电梯!",QMessageBox::Yes);
return;
}
QSqlTableModel *modelTable = new QSqlTableModel(this);
modelTable->setTable("tableLift");
modelTable->select();
for(int i=0;i<modelTable->columnCount();i++)
{
QModelIndex index = modelTable->index(curRow,i);
arrValues.push_back(modelTable->data(index).toString());
}
accept();
}
示例10: slotBtnReadCard
//.........这里部分代码省略.........
(dsSysSwitchCard.structSysSwitchCard.LiftNum[i]&(1<<j)) == pow(2,j)
)
{
nLiftNum=i*8+(j+1);
}
}
}
strTxtbrwInfos+="可用电梯号:"+TypeConvert::intNormal2stdstring(nLiftNum)+"\n";
//受控楼层
strTxtbrwInfos+="受控楼层:";
strTxtbrwInfos+="A门:";
for(int i=0;i<6;i++)
{
for(int j=0;j<8;j++)
{
if
(
(dsSysSwitchCard.structSysSwitchCard.FloorsA[i]&(1<<j)) == pow(2,j)
)
{
int nFloor = i*8+(j+1);
strTxtbrwInfos+=TypeConvert::intNormal2stdstring(nFloor)+",";
}
}
}
strTxtbrwInfos.erase(strTxtbrwInfos.end()-1);
strTxtbrwInfos+="\n";
break;
}
default:
break;
}
break;
}
case 0x0A://通讯地址设定卡
{
strTxtbrwInfos += "卡类型:通讯地址设定卡\n";
int nAddr = chData[2];
strTxtbrwInfos +=
"地址:"+TypeConvert::intNormal2stdstring(nAddr)+"\n";
break;
}
case 0x0B://清内存卡
{
strTxtbrwInfos += "卡类型:清内存卡\n";
break;
}
default:
{
strTxtbrwInfos += "此卡为新卡\n";
break;
}
}
}
else
{
strTxtbrwInfos = "请插入读卡器!";
}
ch375rw.Beep(1);
strQTxtbrwInfos=QString::fromStdString(strTxtbrwInfos);
#endif
static int countClick=0;
countClick++;
switch(countClick)
{
case 1:
{
strQTxtbrwInfos="用户卡\n";
std::vector<QString> arrFiledsUsrCards;
arrFiledsUsrCards.push_back("卡号");
arrFiledsUsrCards.push_back("业主姓名");
arrFiledsUsrCards.push_back("业主门牌");
arrFiledsUsrCards.push_back("联系电话");
arrFiledsUsrCards.push_back("限制日期");
arrFiledsUsrCards.push_back("可用电梯");
arrFiledsUsrCards.push_back("可用楼层");
arrFiledsUsrCards.push_back("房间编号");
QSqlTableModel *modelTableUsrCard = new QSqlTableModel(this);
modelTableUsrCard->setTable("tableUsrCard");
modelTableUsrCard->select();
int rowLast = modelTableUsrCard->rowCount()-1;
for(int i=0;i<8;i++)
{
QModelIndex indexModelLast = modelTableUsrCard->index(rowLast,i);
QString strUsrCardLast = modelTableUsrCard->data(indexModelLast).toString();
strQTxtbrwInfos += arrFiledsUsrCards[i] + ":"+strUsrCardLast+"\n";
}
break;
}
case 2:
{
strQTxtbrwInfos="此卡为新卡!\n";
break;
}
}
txtbrwInfos->setText(strQTxtbrwInfos);
}
示例11: removeSelectedRows
void TableEditor::removeSelectedRows()
{
int currentTab = tabWidget->currentIndex();
QTableView *tv = agentsTable;
QSqlTableModel *stm = agentsModel;
QString table = "agents";
int idColumn = 0;
if (currentTab == 1)
{
tv = determinationsTable;
stm = determinationsModel;
table = "determinations";
}
else if (currentTab == 2)
{
tv = imagesTable;
stm = imagesModel;
table = "images";
idColumn = 20;
}
else if (currentTab == 3)
{
tv = taxaTable;
stm = taxaModel;
table = "taxa";
idColumn = 1;
}
else if (currentTab == 4)
{
tv = organismsTable;
stm = organismsModel;
table = "organisms";
}
else if (currentTab == 5)
{
tv = sensuTable;
stm = sensuModel;
table = "sensu";
}
QItemSelectionModel *selected = tv->selectionModel();
QModelIndexList rowList = selected->selectedIndexes();
for (int i = rowList.count()-1; i >= 0; i--)
{
stm->removeRow(rowList.at(i).row(), rowList.at(i).parent());
QString identifier;
if (table == "determinations")
{
QString orgID = stm->data(stm->index(rowList.at(i).row(),0),Qt::DisplayRole).toString();
QString date = stm->data(stm->index(rowList.at(i).row(),2),Qt::DisplayRole).toString();
QString tsnID = stm->data(stm->index(rowList.at(i).row(),4),Qt::DisplayRole).toString();
QString source = stm->data(stm->index(rowList.at(i).row(),5),Qt::DisplayRole).toString();
reversions.append("INSERT OR REPLACE INTO determinations SELECT * FROM pub_determinations "
"WHERE dsw_identified = '" + orgID + "' AND "
"dwc_dateIdentified = '" + date + "' AND "
"tsnID = '" + tsnID + "' AND "
"nameAccordingToID = '" + source + "' LIMIT 1");
}
else
{
identifier = stm->data(stm->index(rowList.at(i).row(),idColumn),Qt::DisplayRole).toString();
reversions.append("INSERT OR REPLACE INTO " + table + " SELECT * FROM pub_" + table + " WHERE dcterms_identifier = '" + identifier + "' LIMIT 1");
}
}
}