本文整理汇总了C++中QSqlTableModel::setHeaderData方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::setHeaderData方法的具体用法?C++ QSqlTableModel::setHeaderData怎么用?C++ QSqlTableModel::setHeaderData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::setHeaderData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_cbMatricola_currentIndexChanged
void FormGestioneFerie::on_cbMatricola_currentIndexChanged(const QString &arg1)
{
ui->cbCognome->setCurrentIndex(ui->cbMatricola->currentIndex());
QSqlQuery query1(QString("SELECT nome FROM anagrafica where Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
query1.next();
ui->lNome->setText( query1.value(0).toString() );
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);
}
示例2: getVenueModel
QSqlTableModel* MainWindow::getVenueModel()
{
ui->tableView_ven->setModel(NULL);
QSqlTableModel *model = new QSqlTableModel;
model->setTable("venues");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setHeaderData(0, Qt::Horizontal, "ID");
model->setHeaderData(1, Qt::Horizontal, "Name");
return model;
}
示例3: 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);
}
}
示例4: 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);
}
示例5: setModel
void MainWindow::setModel(QTableView *tableViewName, QString modelName, QString tableName, QStringList *tableFields, QString filter, int orderNum)
{
QSqlTableModel *model;
if (modelName == "modelEdit") {
modelEdit = new QSqlTableModel;
model = modelEdit;
} else if (modelName == "modelChoose") {
modelChoose = new QSqlTableModel;
model = modelChoose;
} else if (modelName == "modelQ") {
modelQ = new QSqlTableModel;
model = modelQ;
} else if (modelName == "modelQE") {
modelQE = new QSqlTableModel;
model = modelQE;
} else if (modelName == "modelNote") {
modelNote = new QSqlTableModel;
model = modelNote;
} else if (modelName== "modelNotes") {
modelNotes = new QSqlTableModel;
model = modelNotes;
} else {
return;
}
model= new QSqlTableModel(this);
model->setTable(tableName);
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->setSort(orderNum, Qt::DescendingOrder);
int tableFieldsNum = tableFields->length();
for (int i = 0; i < tableFieldsNum; i++) {
model->setHeaderData(i, Qt::Horizontal, tableFields->at(i));
}
tableViewName->setModel(model);
tableViewName->alternatingRowColors();
tableViewName->horizontalHeader()->setStretchLastSection(true);
model->setFilter(filter);
model->select();
tableViewName->reset();
qDebug() << modelName << model << model->rowCount();
if (modelName == "modelEdit") {
modelEdit = model;
} else if (modelName == "modelChoose") {
modelChoose = model;
} else if (modelName == "modelQ") {
modelQ = model;
} else if (modelName == "modelQE") {
modelQE = model;
} else if (modelName == "modelNote") {
modelNote = model;
} else if (modelName == "modelNotes") {
modelNotes = model;
} else return;
}
示例6: getTableModel
QSqlTableModel* SQLService::getTableModel(QString table){
QSqlTableModel *model = new QSqlTableModel(this, this->db);
model->setTable(table);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
return model;
}
示例7: initBorrowTableView
void AdminDialog::initBorrowTableView()
{
QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
model->setTable("borrow");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select(); //选取整个表的所有行
model->setFilter("isreturn=0");
model->removeColumn(model->columnCount()-1);
model->removeColumn(model->columnCount()-1);
model->setHeaderData(0,Qt::Horizontal,"借阅编号");
model->setHeaderData(1,Qt::Horizontal,"图书编号");
model->setHeaderData(2,Qt::Horizontal,"读者编号");
model->setHeaderData(3,Qt::Horizontal,"剩余续借次数");
model->setHeaderData(4,Qt::Horizontal,"借阅时间");
model->setHeaderData(5,Qt::Horizontal,"应还时间");
ui->tv3->setModel(model);
ui->tv3->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
示例8: findCellInfo
void Control::findCellInfo()
{
if(!checkDurationValid())
{
QMessageBox::warning(this,"警告","请选择正确的时间段",QMessageBox::Yes);
return;
}
if(ui->lineEdit->text().isEmpty())
{
QMessageBox::warning(this,"警告","请输入拥塞门限(0到1的小数)",QMessageBox::Yes);
return;
}
double rate= ui->lineEdit->text().toDouble();
QSqlQuery query;
query.exec("exec countCongs");
QDateTime start = ui->startDateTimeEdit->dateTime();
QDateTime end = ui->endDateTimeEdit->dateTime();
int year1 = start.date().year() % 10 * 10000;
int month1 = start.date().month() * 100;
int day1 = start.date().day();
int hour1 = start.time().hour();
int year2 = end.date().year() % 10 * 10000;
int month2 = end.date().month() * 100;
int day2 = end.date().day();
int hour2 = end.time().hour();
query.exec(QString("exec finder2 %1,%2,%3,%4,%5").arg(rate).arg(year1 + month1 + day1).arg(hour1)
.arg(year2 + month2 + day2).arg(hour2));//finder2只列rate超过门限的部分数据
QSqlTableModel* model = new QSqlTableModel(this);
model->setTable("H_result");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setFilter("H_rate>"+QString::number(rate) +" order by CellID,bdate,btime");
model->setHeaderData(0,Qt::Horizontal,tr("日期"));
model->setHeaderData(1,Qt::Horizontal,tr("小时"));
model->setHeaderData(2,Qt::Horizontal,tr("小区ID"));
model->setHeaderData(3,Qt::Horizontal,tr("小时级话务量"));
model->setHeaderData(4,Qt::Horizontal,tr("小时级拥塞率"));
model->setHeaderData(5,Qt::Horizontal,tr("小时级半速率话务量比例"));
model->select();
ui->tableView_2->setModel(model);
ui->tableView_2->show();
}
示例9: query
FormGestioneFerie::FormGestioneFerie(QSqlDatabase db, QWidget *parent) :
QWidget(parent),
ui(new Ui::FormGestioneFerie)
{
ui->setupUi(this);
QDate oggi;
ui->dePermessiDal->setDate(oggi.currentDate());
ui->dePermessiAl->setDate(oggi.currentDate());
this->db= db;
QSqlQuery query(QString("SELECT Matricola,cognome FROM anagrafica"));
while (query.next())
{
ui->cbMatricola->addItem( query.value(0).toString() );
ui->cbCognome->addItem( query.value(1).toString() );
ui->lNome->setText( query.value(2).toString() );
}
QSqlQuery query1(QString("SELECT nome FROM anagrafica where Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
query1.next();
ui->lNome->setText( query1.value(0).toString() );
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);
}
示例10: QWidget
TableView::TableView()
: QWidget()
{
if (! this->createConnection()) {
QString msg = "** Create Database Error";
throw msg;
}
setWindowTitle(tr("Table View Model"));
setMinimumSize(300, 350);
//
QSqlTableModel *model = new QSqlTableModel(this, m_db);
QStringList tempX = m_db.tables();
model->setTable(tempX.at(0));
QSqlError error = model->lastError();
if ( error.isValid() ) {
ksMsg( this, "Table View - SQL Error", error.text() );
}
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setSort(2, Qt::AscendingOrder);
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
//
QTableView *view = new QTableView;
view->setModel(model);
view->resizeColumnsToContents();
QHeaderView *temp = view->horizontalHeader();
temp->setStretchLastSection(true);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
setLayout(mainLayout);
}
示例11: on_pushButton_clicked
/*----------查询数据库全体-------------*/
void DataDialog::on_pushButton_clicked()
{
QSqlQuery query;
query.exec("drop view if exists temp");
query.exec("create view temp as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata)");
if(!query.isActive())
{
if(QSqlDatabase::database().open())
{
query.exec("drop view if exists temp");
query.exec("create view temp as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata)");
}
}//重连数据库
QSqlTableModel *m = new QSqlTableModel(this);
m->setTable("temp");
m->select();
m->setHeaderData(0,Qt::Horizontal,tr("编号"));
m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
ui->tableView->setModel(m);
}
示例12: on_nodeList_currentIndexChanged
/*------------根据节点编号筛选查询数据库------------*/
void DataDialog::on_nodeList_currentIndexChanged(const QString &arg1)
{
QSqlTableModel *m = new QSqlTableModel(this);
if(arg1==tr("全部"))
{
on_pushButton_clicked();
return ;
}
else
{
QSqlQuery query;
query.exec("drop view if exists temp2");
QString sql = QString("create view temp2 as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata where gatewayNo = %1)").arg(arg1.toInt());
qDebug() << "sql = " << sql;
query.exec(sql);
m->setTable("temp2");
m->select();
m->setHeaderData(0,Qt::Horizontal,tr("编号"));
m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
ui->tableView->setModel(m);
}
}
示例13: on_tvPermessi_doubleClicked
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);
}
}
}
示例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: on_nameList_currentIndexChanged
/*----------根据污染元筛选查询数据库-------------*/
void DataDialog::on_nameList_currentIndexChanged(const QString &arg1)
{
//建立code和name的对应关系方便显示
mapCodeName mCodeName[] =
{{"1_voltage","电压"}, {"1_light","光照"}, {"1_a01001","温度"}, {"1_a01002","湿度"},
{"2_a01001_e","外部温度"}, {"2_a01001_i","内部温度"}, {"2_a06003","PH"}, {"2_a06001","雨量"},
{"2_a01007","风速"}, {"2_a01008","风向"}, {"2_voltage","电源电压"}, {"2_a06002","是否降雨"},
{"3_a01001_30","温度(30cm)"}, {"3_a01002_30","湿度(30cm)"}, {"3_a01001_15","温度(15cm)"},
{"3_a01002_15","湿度(15cm)"}, {"3_a01001_05","温度(5cm)"}, {"3_a01002_05","湿度(5cm)"},
{"4_a01001","温度"}, {"4_a01002","湿度"}, {"4_w01008_v","垂直盐分"}, {"4_w01008_s","表面盐分"}};
enum {LENGTH_M = 22};
QMap<QString,QString>nameCode;
for(int i = 0; i < LENGTH_M; i++)
{
nameCode.insert(tr(mCodeName[i].name),mCodeName[i].code);
}
QSqlTableModel *m = new QSqlTableModel(this);
if(arg1==tr("全部"))
{
on_pushButton_clicked();
return ;
}
else
{
QSqlQuery query;
query.exec("drop view if exists temp1");
QString sql = QString("create view temp1 as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata where code = '%1')").arg(nameCode[arg1]);
qDebug() << "sql = " << sql;
query.exec(sql);
m->setTable("temp1");
m->select();
m->setHeaderData(0,Qt::Horizontal,tr("编号"));
m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
ui->tableView->setModel(m);
}
}