本文整理汇总了C++中QSqlQueryModel类的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQueryModel类的具体用法?C++ QSqlQueryModel怎么用?C++ QSqlQueryModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlQueryModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: query
QSqlQueryModel * DatabaseHandler::getCloseObjects(census * obj) {
QSqlQueryModel * model = new QSqlQueryModel;
QString qstr = "SELECT sync_id FROM sync_utm32 WHERE cam" + obj->camera + "_id='"
+ obj->image + "'";
QSqlQuery query(qstr);
int sync_id;
if (query.next())
sync_id = query.value(0).toInt();
else {
qDebug() << qstr;
return model;
}
query.clear();
QStringList sidList = QStringList() << QString::number(sync_id-1) << QString::number(sync_id)
<< QString::number(sync_id+1);
qstr = "SELECT cam, img FROM image_properties WHERE sync_id IN (" +sidList.join(",")+ ")";
query.exec(qstr);
QStringList condList;
while(query.next()) {
condList.append("(cam='" + query.value(0).toString()
+ "' AND img='" +query.value(1).toString()+ "')");
}
/*
* TODO: Add distance comparison
*/
qstr = "SELECT rcns_id, cam, img, ux, uy, tp, "
"ST_Distance( (SELECT ST_SetSRID(ST_Point(ux,uy),32632) FROM raw_census "
"where rcns_id=" + QString::number(obj->id) + ") "
", ST_SetSRID(ST_Point(ux,uy),32632) ) as dist FROM raw_census "
"WHERE (" + condList.join(" OR ") + ") AND rcns_id!=" + QString::number(obj->id) +
" AND session='" + obj->session + "' ORDER BY dist";
qDebug() << qstr;
model->setQuery(qstr);
model->setHeaderData(0, Qt::Horizontal, "Object Id");
model->setHeaderData(1, Qt::Horizontal, "Kamera");
model->setHeaderData(2, Qt::Horizontal, "Bildnummer");
model->setHeaderData(3, Qt::Horizontal, "UTM X");
model->setHeaderData(4, Qt::Horizontal, "UTM Y");
model->setHeaderData(5, Qt::Horizontal, "Vorsortierung");
model->setHeaderData(6, Qt::Horizontal, "Entfernung in m");
return model;
}
示例2: QDialog
estore::estore(QWidget *parent) :
QDialog(parent),
ui(new Ui::estore)
{
ui->setupUi(this);
setFixedSize(670,290);
setWindowTitle("商城");
QSqlQueryModel *mode = new QSqlQueryModel(ui->tableView); //建立一个Model
mode->setQuery("select * from commodity") ;
mode->setHeaderData(0,Qt::Horizontal,QObject::tr("编号"));
mode->setHeaderData(1,Qt::Horizontal,QObject::tr("名称"));
mode->setHeaderData(2,Qt::Horizontal,QObject::tr("描述"));
mode->setHeaderData(3,Qt::Horizontal,QObject::tr("原价"));
mode->setHeaderData(4,Qt::Horizontal,QObject::tr("售价"));
mode->setHeaderData(5,Qt::Horizontal,QObject::tr("种类"));
mode->setHeaderData(6,Qt::Horizontal,QObject::tr("数量"));
mode->setHeaderData(7,Qt::Horizontal,QObject::tr("折扣"));
mode->setHeaderData(8,Qt::Horizontal,QObject::tr("出版社/品牌"));
mode->setHeaderData(9,Qt::Horizontal,QObject::tr("ISBN/材料/类别"));
mode->setHeaderData(10,Qt::Horizontal,QObject::tr("日期"));
mode->setHeaderData(11,Qt::Horizontal,QObject::tr("页数/型号/重量"));
ui->tableView->setModel(mode);
}
示例3: QWidget
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setFixedSize(750, 500);
ui->stackedWidget->setCurrentIndex(0);
QSqlQueryModel *typeModel = new QSqlQueryModel(this);
typeModel->setQuery("select name from type");
ui->sellTypeComboBox->setModel(typeModel);
QSplitter *splitter = new QSplitter(ui->managePage);
splitter->resize(700, 360);
splitter->move(0, 50);
splitter->addWidget(ui->toolBox);
splitter->addWidget(ui->dailyList);
splitter->setStretchFactor(0, 1);
splitter->setStretchFactor(1, 1);
on_sellCancelBtn_clicked();
}
示例4: qDebug
QList<int> DataBank::listTable()
{
QList<int> list;
bool ok = false;
if(!database.open()){
qDebug()<<"database database is error";
}else{
qDebug()<<"database database is ok";
}
/*查询数据库中的所有表名*/
QSqlQueryModel model;
model.setQuery("select name from sqlite_master where type='table'",database);
for(int i = 0; i < model.rowCount(); ++i){
QString name = model.record(i).value("name").toString();
list.append(name.mid(5,2).toInt(&ok ,10));
}
database.close();
return list;
}
示例5: QWidget
DashboardWindow::DashboardWindow(QWidget *parent, bool isRelative, QString ID) :
QWidget(parent),
ui(new Ui::DashboardWindow)
{
ui->setupUi(this);
//qDebug() << ID;
m_RelativeID = ID;
if (isRelative)
{
//qDebug() << "Is relative";
ui->stackedWidget->setCurrentIndex(1);
on_pushButton_overview_clicked();
ui->pushButton_overview->setChecked(1);
}
else {
ui->stackedWidget->setCurrentIndex(0);
QSqlQueryModel *model = new QSqlQueryModel;
QString query = "SELECT COUNT(*) FROM INMATE";
model->setQuery(query);
ui->txtInmateCount->setText("Number of inmates: " + model->data(model->index(0, 0)).toString());
query = "SELECT COUNT(*) FROM RE_LATIVE";
model->setQuery(query);
ui->txtRelativeCount->setText("Number of relatives: " + model->data(model->index(0, 0)).toString());
query = "SELECT COUNT(*) FROM OFFICER";
model->setQuery(query);
ui->txtOfficerCount->setText("Number of officers: " + model->data(model->index(0, 0)).toString());
}
}
示例6: QSqlQueryModel
QSqlQueryModel *DatabaseManager::getPrestable(int idtransaccion,QWidget* parentWidget)
{
QSqlQueryModel *model = new QSqlQueryModel(parentWidget);
if(!db.open()){ QMessageBox::critical(0,"Database Error",db.lastError().text()); return model; }
QSqlQuery preQuery;
preQuery.exec(QString("SELECT * FROM transacciones WHERE idtransaccion = '%1' LIMIT 1;"
).arg(idtransaccion));
if(!preQuery.next())
{
//There is a record in the table with this same information
qDebug() << "Transaction does not exist";
return model;
}
//TODO what the hell is going on here?
model->setQuery(QString("SELECT marca,modelo,observaciones,idserie,dimension FROM prestables right join balanzas on prestables.balanzas_idbalanza = balanzas.idbalanza where idprestable = (select transacciones.prestables_idprestable from transacciones where idtransaccion = '2');"));
// model->setQuery(QString("SELECT * FROM transacciones;"));
bool ret = true;
if(ret)
{
qDebug() << "Row count" << model->rowCount();
return model;
}
else
{
qDebug() << model->lastError().text();
return model;
}
}
示例7: setModel
void SqlItemView::setModel(QAbstractItemModel * model)
{
m_model = model;
QSqlQueryModel * t = qobject_cast<QSqlQueryModel *>(model);
if (!t) { return; }
QSqlRecord rec(t->record());
if (scrollWidget->widget())
{
delete scrollWidget->takeWidget();
}
QWidget * layoutWidget = new QWidget(scrollWidget);
m_gridLayout = new QGridLayout(layoutWidget);
QString tmp("%1:");
for (int i = 0; i < rec.count(); ++i)
{
m_gridLayout->addWidget(
new QLabel(tmp.arg(rec.fieldName(i)), layoutWidget), i, 0);
QTextEdit * w = new QTextEdit(layoutWidget);
w->setReadOnly(false);
w->setAcceptRichText(false);
int mh = QFontMetrics(w->currentFont()).lineSpacing();
w->setMinimumHeight(mh);
w->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::MinimumExpanding);
m_gridLayout->addWidget(w, i, 1);
m_gridLayout->setRowMinimumHeight(i, mh);
connect(w, SIGNAL(textChanged()),
this, SLOT(textChanged()));
}
scrollWidget->setWidget(layoutWidget);
m_count = rec.count();
}
示例8: if
void EvictionWindow::on_searchBtn_clicked()
{
DataBase db;
db.connectionOpen();
QSqlQuery query;
QString searchText = ui->searchEdit->text();
if(searchText == ""){
query.prepare("select * from clients");
} else if(ui->searchType->currentText() == "Номеру комнаты") {
query.prepare("select * from clients where roomNumber=" + searchText);
} else if(ui->searchType->currentText() == "Имени") {
query.prepare("select * from clients where firstName like '%" + searchText + "%'");
} else if(ui->searchType->currentText() == "Фамилии") {
query.prepare("select * from clients where lastName like '%" + searchText + "%'");
} else if(ui->searchType->currentText() == "Паспорту") {
query.prepare("select * from clients where passport like '%" + searchText + "%'");
}
query.exec();
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery(query);
model->QSqlQueryModel::setHeaderData(0, Qt::Horizontal, "ID");
model->QSqlQueryModel::setHeaderData(1, Qt::Horizontal, "Имя");
model->QSqlQueryModel::setHeaderData(2, Qt::Horizontal, "Фамилия");
model->QSqlQueryModel::setHeaderData(3, Qt::Horizontal, "Паспорт");
model->QSqlQueryModel::setHeaderData(4, Qt::Horizontal, "Количество дней");
model->QSqlQueryModel::setHeaderData(5, Qt::Horizontal, "Дата посления");
model->QSqlQueryModel::setHeaderData(6, Qt::Horizontal, "№ комнаты");
model->QSqlQueryModel::setHeaderData(7, Qt::Horizontal, "Тип комнаты");
ui->tableView->setModel(model);
ui->tableView->resizeColumnToContents(4);
ui->tableView->resizeColumnToContents(5);
db.connectionClose();
}
示例9: Principal
void pandasoft::Principal()
{
ui->error->hide();
ui->error0->hide();
ui->usuario->setStyleSheet("background-color: none;");
ui->clave->setStyleSheet("background-color: none;");
if(ui->usuario->text().isEmpty()||ui->clave->text().isEmpty()){
if(ui->usuario->text().isEmpty()){
ui->error->show();
ui->usuario->setStyleSheet("background-color: red;");
}
if(ui->clave->text().isEmpty()){
ui->error->show();
ui->clave->setStyleSheet("background-color: red;");
}
}
else {
QSqlQueryModel model;
QString consulta="select Nombre, Ap, Am, Rol from Usuario where (Nombre='"+ui->usuario->text()+"' and Contrasena='"+ui->clave->text()+"' )";
model.setQuery(consulta);
if(model.record(0).value("Rol").toString()==""){
ui->error0->show();
}else{
QString rol = model.record(0).value("Rol").toString();
rolusu=rol;
QString usuario = model.record(0).value("Nombre").toString()+" "+model.record(0).value("Ap").toString()+" "+model.record(0).value("Am").toString();
this->setWindowTitle("Principal");
ui->pandasoftstackedWidget->setCurrentIndex(1);
ui->menubar->show();
if(rolusu=="1"){
ui->menuMenu_Gerente->setEnabled(false);
ui->cabecera->setText("Bienvenido Usuario: "+usuario+" Rol : Jefe de Almacen");
}else{
ui->cabecera->setText("Bienvenido Usuario: "+usuario+" Rol : Gerente");
}
}
ui->alertalista->setEnabled(false);
QString alerta="select Nombre from Producto where Cantidad<Lim_stock";
model.setQuery(alerta);
ui->alertalista->setText(model.record(0).value("Nombre").toString());
}
}
示例10: store_Show
//点击音乐库按钮
void MusicWindow::store_Show()
{
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("select * from music_songs");
model->setHeaderData(0, Qt::Horizontal, tr("The name of songs"));
model->setHeaderData(1, Qt::Horizontal, tr("The number of mark"));
ui->storeView->setModel(model);
ui->storeView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); //表头居中
ui->storeView->setColumnWidth(0, 355);//设置固定列宽
ui->storeView->setColumnWidth(1, 355);
titlePalette = ui->storeButton->palette();
titlePalette.setColor(QPalette::ButtonText, Qt::red);
ui->storeButton->setPalette(titlePalette);
titlePalette.setColor(QPalette::ButtonText,Qt::white);
ui->browserButton->setPalette(titlePalette);
ui->favoriteButton->setPalette(titlePalette);
ui->webView->hide();
ui->favoriteView->hide();
ui->storeView->show();
}
示例11: while
void viewActivityAllCourses::on_comboBox_currentIndexChanged()
{
QSqlQuery qry;
QString courseid,course;
course = ui->comboBox->currentText();
qry.exec("select courseID from Courses where courseName='"+course+"'");
while(qry.next()){
courseid = qry.value(0).toString();
}
//activity table
QSqlQueryModel * modal = new QSqlQueryModel();
QSqlQuery qry2;//= new QSqlQuery(conn2.mydb);
qry2.prepare("select activityname from activity where courseid='"+courseid+"'");
qry2.exec();
modal->setQuery(qry2);
ui->tableView->setModel(modal);
}
示例12: populateClienteField
void DetalleCompraVenta::populateClienteField()
{
QSqlQueryModel cliente;
cliente.setQuery ("SELECT nombre,cuit FROM cliente ORDER BY nombre");
for(int i=0; i < cliente.rowCount(); i++)
{
ui->cliente->addItem( cliente.data(cliente.index(i,0)).toString(), QVariant( cliente.data(cliente.index(i,1)).toDouble()));
}
}
示例13: QString
void SingleWeatherParamWidget::onAirportChanged(QString apCode, QString pName){
//清空
QList<int> keyList = editHash.keys();
for(int key : keyList){
QList<QLineEdit *> editList = editHash[key];
for(QLineEdit *edit : editList){
edit->setText("");
}
}
//赋值
currentApCode = apCode;
currentPName = pName;
weatherParamSetupList.clear();
QString queryStr = QString("select * from weatherparamsetup where code = '%1' and planename = '%2' order by paramid")
.arg(currentApCode)
.arg(currentPName);
QSqlQueryModel *plainModel = pgDb->queryModel(queryStr);
int rowCount = plainModel->rowCount();
for(int i = 0;i < rowCount;i++){
WeatherParamSetup weatherParamSetup;
weatherParamSetup.setCode(plainModel->record(i).value(0).toString());
weatherParamSetup.setPlaneName(plainModel->record(i).value(1).toString());
weatherParamSetup.setParamid(plainModel->record(i).value(2).toInt());
weatherParamSetup.setLimits(plainModel->record(i).value(3).toString());
bool isExist = false;
for(WeatherParam weatherParam : weatherParamList){
if(weatherParam.id() == weatherParamSetup.paramid()){
isExist = true;
break;
}
}
if(isExist){
weatherParamSetupList.append(weatherParamSetup);
}
}
delete plainModel;
for(WeatherParamSetup weatherParamSetup : weatherParamSetupList){
int key = weatherParamSetup.paramid();
QString limitJson = weatherParamSetup.limits();
QList<QString> valueList = this->getDataFromJson(limitJson);
QList<QLineEdit *> editList = editHash[key];
int valueCount = valueList.count();
int editCount = editList.count();
for(int i = 0;i < editCount;i++){
QLineEdit *edit = editList[i];
if(valueCount != editCount){
edit->setText("");
}else{
edit->setText(valueList[i]);
}
}
}
}
示例14: max
QSqlQueryModel * DatabaseHandler::getImageObjects(census * obj) {
QSqlQueryModel * model = new QSqlQueryModel;
QString qstr = "SELECT rcns_id, tp, ux, uy, max(censor), count(*) FROM view_census WHERE cam='" +
obj->camera + "' AND img='" + obj->image + "' AND session='"
+ obj->session + "' AND (censor>0 OR censor IS NULL) GROUP BY rcns_id, tp, ux, uy ORDER BY rcns_id";
qDebug() << qstr;
model->setQuery(qstr);
model->setHeaderData(0, Qt::Horizontal, "Objekt Id");
model->setHeaderData(1, Qt::Horizontal, "Typ");
model->setHeaderData(2, Qt::Horizontal, "UTM X");
model->setHeaderData(3, Qt::Horizontal, "UTM Y");
model->setHeaderData(4, Qt::Horizontal, "Highest censor");
model->setHeaderData(5, Qt::Horizontal, "Censor count");
return model;
}
示例15: while
void So2sdr::populateDupesheet()
// populates dupe sheet. Needs to be called when switching bands
// or first turning on the dupesheet
{
// if only one dupesheet is active, figure out which one it is
bool oneactive=false;
int nr=0;
if (nDupesheet==1) {
oneactive=true;
for (int i=0;i<2;i++) {
if (!dupesheet[i]) continue;
if (dupesheet[i]->isVisible()) {
nr=i;
break;
}
}
}
for (int id=0;id<2;id++) {
if (!dupesheet[id]) continue;
int ib=id;
if (oneactive) {
if (nr!=id) continue;
ib=activeRadio;
}
dupesheet[id]->Dupes0->clear();
dupesheet[id]->Dupes1->clear();
dupesheet[id]->Dupes2->clear();
dupesheet[id]->Dupes3->clear();
dupesheet[id]->Dupes4->clear();
dupesheet[id]->Dupes5->clear();
dupesheet[id]->Dupes6->clear();
dupesheet[id]->Dupes7->clear();
dupesheet[id]->Dupes8->clear();
dupesheet[id]->Dupes9->clear();
for (int i = 0; i < dsColumns; i++) {
dupeCalls[id][i].clear();
dupeCallsKey[id][i].clear();
}
QSqlQueryModel m;
m.setQuery("SELECT * FROM log WHERE valid='true' and BAND=" + QString::number(band[ib]), mylog->db);
while (m.canFetchMore()) {
m.fetchMore();
}
for (int i = 0; i < m.rowCount(); i++) {
QByteArray tmp = m.record(i).value("call").toString().toAscii();
updateDupesheet(tmp,id);
}
dupesheet[id]->setWindowTitle("Dupesheet " + bandName[band[ib]]);
}
}