当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlQueryModel::rowCount方法代码示例

本文整理汇总了C++中QSqlQueryModel::rowCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQueryModel::rowCount方法的具体用法?C++ QSqlQueryModel::rowCount怎么用?C++ QSqlQueryModel::rowCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSqlQueryModel的用法示例。


在下文中一共展示了QSqlQueryModel::rowCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetDb

void PringKvitok::SetDb(db *mdb)
{
    myDB = mdb;
     ui->comboBox_groups->addItem("Выбрать все", "s_all");
    ui->comboBox_groups->addItem("Снять все", "d_all");
    QSqlQueryModel *groups = myDB->Query("SELECT * FROM groups WHERE id > 2");
    for(int i = 0; i < groups->rowCount(); i++){
         ui->comboBox_groups->addItem(groups->record(i).value("name").toString(), groups->record(i).value("id").toString());
    }

    childsCheckBox_map.clear();
   QString sql = "SELECT t0.id, t0.group_id, t0.fio,  t1.name AS group_name, t0.ls FROM childs t0";
    sql += " LEFT OUTER  JOIN groups  t1 ON t0.group_id = t1.id";
    QSqlQueryModel *childs = myDB->Query(sql);
    for(int i = 0; i < childs->rowCount(); i++){
          QString childs_id = childs->record(i).value("id").toString();
          ui->tW->insertRow(ui->tW->rowCount());
          ui->tW->setItem(ui->tW->rowCount() - 1, 1,new QTableWidgetItem(childs->record(i).value("fio").toString()));
          ui->tW->setItem(ui->tW->rowCount() - 1, 2,new QTableWidgetItem(childs->record(i).value("group_name").toString()));
          ui->tW->setItem(ui->tW->rowCount() - 1, 3,new QTableWidgetItem(childs_id));
          ui->tW->setItem(ui->tW->rowCount() - 1, 4,new QTableWidgetItem(childs->record(i).value("group_id").toString()));
          ui->tW->setItem(ui->tW->rowCount() - 1, 5,new QTableWidgetItem(childs->record(i).value("ls").toString()));
          QCheckBox *cb = new QCheckBox();
          cb->setText(childs_id);
          connect(cb , SIGNAL( toggled(bool) ), this, SLOT( on_childs_toggled(bool)) );
          childsCheckBox_map[childs_id] = cb;
          ui->tW->setCellWidget(ui->tW->rowCount() - 1, 0, cb);

     }
    delete groups;
    delete childs;

}
开发者ID:haltxz,项目名称:ds,代码行数:33,代码来源:pringkvitok.cpp

示例2: on_btmBuscar_clicked

void mantenimientoTitulo::on_btmBuscar_clicked()
{
    if(m_ui->btmTitulo->isChecked()) {

        QSqlQueryModel *model = new QSqlQueryModel(m_ui->titulos);
        model->setQuery("SELECT tituloObra, isbn FROM titulo WHERE tituloObra LIKE '%"+m_ui->busqueda->text()+"%';", QSqlDatabase::database("sibcues"));
        if (model->lastError().isValid())
            qDebug() << model->lastError();

        model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico"));
        model->setHeaderData(1, Qt::Horizontal, QObject::tr("ISBN"));
        m_ui->titulos->setModel(model);
        connect(m_ui->titulos->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_titulos_activated(QModelIndex)));
        m_ui->labelTitulo->setText("Titulos: "+QString::number(model->rowCount())+" resultados.");
    }
    else {

        QSqlQueryModel *model = new QSqlQueryModel(m_ui->titulos);
        model->setQuery("SELECT titulo.tituloObra, titulo.isbn FROM obrade left join titulo on titulo.idTitulo=obrade.idTitulo left join autor on obrade.idAutor=autor.idAutor WHERE autor.nombreAutor LIKE '%"+m_ui->busqueda->text()+"%';", QSqlDatabase::database("sibcues"));

        if (model->lastError().isValid())
            qDebug() << model->lastError();

        model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico"));
        model->setHeaderData(1, Qt::Horizontal, QObject::tr("ISBN"));
        m_ui->titulos->setModel(model);
        connect(m_ui->titulos->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_titulos_activated(QModelIndex)));
        m_ui->labelTitulo->setText("Titulos: "+QString::number(model->rowCount())+" resultados.");
    }
}
开发者ID:bagonzalez,项目名称:SI-BCUES,代码行数:30,代码来源:mantenimientotitulo.cpp

示例3: lastNr

/*!
   qso number sent for last qso in log
 */
int Log::lastNr() const
{
    QSqlQueryModel m;
#if QT_VERSION < 0x050000
    m.setQuery("SELECT * FROM log where valid='true'", db);
#else
    m.setQuery("SELECT * FROM log where valid=1", db);
#endif
    while (m.canFetchMore()) {
        m.fetchMore();
    }
    if (m.rowCount()) {
        QByteArray snt[MAX_EXCH_FIELDS];
        snt[0] = m.record(m.rowCount() - 1).value(SQL_COL_SNT1).toByteArray();
        snt[1] = m.record(m.rowCount() - 1).value(SQL_COL_SNT2).toByteArray();
        snt[2] = m.record(m.rowCount() - 1).value(SQL_COL_SNT3).toByteArray();
        snt[3] = m.record(m.rowCount() - 1).value(SQL_COL_SNT4).toByteArray();
        bool ok = false;
        int  nr = snt[nrField].toInt(&ok, 10);
        if (!ok) nr = 0;
        return(nr);
    } else {
        return(0);
    }
}
开发者ID:n4ogw,项目名称:so2sdr,代码行数:28,代码来源:log.cpp

示例4: categoryList

ServiceBlock::ServiceBlock(int idC, QWidget *parent) :
    QDialog(parent),
    idCar(idC),
    ui(new Ui::ServiceBlock)
{
    ui->setupUi(this);

    setCalendarColor(ui->deBegin->calendarWidget(),QColor(255,140,0));
    setCalendarColor(ui->deEnd->calendarWidget(),QColor(255,140,0));
    setCalendarColor(ui->deEvent->calendarWidget(),QColor(255,140,0));
    setCalendarColor(ui->deGuarantee->calendarWidget(),QColor(255,140,0));

    QSqlQueryModel * windTitle = new QSqlQueryModel(this);
    windTitle->setQuery(QString("SELECT Brand, Model, LicensePlate FROM car WHERE idCar = %1").arg(idCar));
    this->setWindowTitle( QString("Naprawy - ")
                          + windTitle->data(windTitle->index(windTitle->rowCount()-1,0)).toString() + QString(" ")
                          + windTitle->data(windTitle->index(windTitle->rowCount()-1,1)).toString() + QString(" - ")
                          + windTitle->data(windTitle->index(windTitle->rowCount()-1,2)).toString()
                          );

    connect(this,SIGNAL(saved()),this,SLOT(updateView()),Qt::DirectConnection);
    connect(this,SIGNAL(deleted()),this,SLOT(updateView()));

    // fill category combobox
    QStringList categoryList({QString("Silnik"),QString("Zawieszenie"),QString("Elektronika"),
                             QString("Elektryka"),QString("Układ napędowy"),QString("Układ hamulcowy"),
                             QString("Układ kierowniczy"),QString("Nadwozie")});
    ui->cbCategory->addItems(categoryList);

    updateView();

    isOpen = true;
}
开发者ID:RStravinsky,项目名称:CarReservation,代码行数:33,代码来源:serviceblock.cpp

示例5: tableLoad

void DataBank::tableLoad(struct Table0 *t,unsigned int i)
{
    QString name = "table";
    name.append(QString::number(i ,10));
    QString sql = QString("select * from '%1'").arg(name);

    if(!database.open()){
        qDebug()<<"database database is error";
    }else{
        qDebug()<<"database database is ok";
    }

    QSqlQueryModel model;
    model.setQuery(sql,database);

    for(int i = 0; i < model.rowCount(); ++i){
        t->Nummber[i] = model.record(i).value("number").toInt();
        t->Shendu[i] = model.record(i).value("shendu").toLongLong();
        t->Jixing[i] = model.record(i).value("jixing").toInt();
        t->Dianliu[i] = model.record(i).value("dianliu").toInt();
        t->Maikuan[i] = model.record(i).value("maikuan").toInt();
        t->Xiuzhi[i] = model.record(i).value("xiuzhi").toInt();
        t->Jianxi[i] = model.record(i).value("jianxi").toInt();
        t->Sudu[i] = model.record(i).value("sudu").toInt();
        t->Shenggao[i] = model.record(i).value("shenggao").toInt();
        t->Gongshi[i] = model.record(i).value("gongshi").toInt();
        t->LV[i] = model.record(i).value("lv").toInt();
        t->Gaoya[i] = model.record(i).value("gaoya").toInt();
        t->PPP[i] = model.record(i).value("ppp").toInt();
        t->WCLC[i] = model.record(i).value("wclc").toInt();
    }

    database.close();
}
开发者ID:taiyuankejizhu,项目名称:SparkZNC,代码行数:34,代码来源:databank.cpp

示例6: addEvent

void Calendar::addEvent()
{
    EventDialog dialog(this);
    dialog.setModal(true);

    if(dialog.exec() == QDialog::Accepted)
    {
        Event tmpEvent = dialog.getEvent();
        qDebug() << tmpEvent.name();

        if((!tmpEvent.name().isEmpty()) || (!tmpEvent.description().isEmpty()))
        {
            QSqlQueryModel check;
            check.setQuery("SELECT * FROM events WHERE date_time='" + tmpEvent.dateTime().toString(m_dateFormat) + "'", m_db);
            if(check.rowCount() == 0)
            {
                QSqlQuery insertion(m_db);
                insertion.prepare("INSERT INTO events(name, description, date_time) VALUES"
                                  "(?,?,?)");
                insertion.addBindValue(tmpEvent.name());
                insertion.addBindValue(tmpEvent.description());
                insertion.addBindValue(tmpEvent.dateTime().toString(m_dateFormat));
                insertion.exec();
                qDebug() << "Pushed";
                m_sqlTableModel->select();
            }
            else
            {
                //Item with this date already exists
                QMessageBox::warning(this, tr("Calendar"), tr("Item with this date and time already exists."));
            }
        }
    }
}
开发者ID:mariusz-ba,项目名称:Calendar,代码行数:34,代码来源:calendar.cpp

示例7: on_pushButton_update_clicked

void AdminPatients::on_pushButton_update_clicked()
{

    QSqlQueryModel * model = new QSqlQueryModel();

    QSqlQuery * qry = new QSqlQuery(mydb);

    qry->prepare("select name,surname from patients");
    qry->exec();
    model->setQuery(*qry);
    ui->tableView->setModel(model);



    QSqlQuery * qry1 = new QSqlQuery(mydb);
    QSqlQueryModel * model1 = new QSqlQueryModel();

           qry1->prepare("select name, surname from patients where doctor is null  ");
           qry1->exec();
           model1->setQuery(*qry1);
           ui->tableView_noDoc->setModel(model1);


    QSqlQuery * qry2 = new QSqlQuery(mydb);
    QSqlQueryModel * model2 = new QSqlQueryModel();

           qry2->prepare("select name, surname,doctor from patients where diagnose is null");
           qry2->exec();
           model2->setQuery(*qry2);
           ui->tableView_noDiag->setModel(model2);



    qDebug()<<(model->rowCount());
}
开发者ID:KarinaChumak,项目名称:KPIrepository,代码行数:35,代码来源:adminpatients.cpp

示例8: QDialog

mantenimientoTitulo::mantenimientoTitulo(int idUnidad, QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::mantenimientoTitulo)
{
    m_ui->setupUi(this);

    m_ui->btmTitulo->setChecked(true);


    Persistencia::Persistencia *servicioPersistencia=new Persistencia(idUnidad);

    QSqlQueryModel *model = new QSqlQueryModel(m_ui->titulos);
    model->setQuery("SELECT tituloObra, isbn FROM titulo;", QSqlDatabase::database("sibcues"));
    if (model->lastError().isValid())
        qDebug() << model->lastError();

    //model->setTable("titulo");
    //model->select();

    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("ISBN"));
    m_ui->titulos->setModel(model);
    m_ui->titulos->alternatingRowColors();
    //m_ui->titulos->hideColumn(0);
    m_ui->titulos->horizontalHeader()->resizeSection(0, 350);
    m_ui->titulos->setSelectionMode(QAbstractItemView::SingleSelection);
    connect(m_ui->titulos->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_titulos_activated(QModelIndex)));
    m_ui->labelTitulo->setText("Titulos: "+QString::number(model->rowCount())+" resultados.");


}
开发者ID:bagonzalez,项目名称:SI-BCUES,代码行数:31,代码来源:mantenimientotitulo.cpp

示例9:

QSqlQueryModel * LazyWord::GetLibModel()		//Get the Date which the user want to show by degree selected
{
	GetSelect GS;		//more see about class GetSelect 
	int FS = GS.Select(show_StrangeBox->isChecked(),show_UnderstandBox->isChecked(),show_MasterBox->isChecked()
	,show_AllBox->isChecked());	
	//qDebug("FO = %d,IO = %d",FS,IO);
	
	QSqlQueryModel * LibModel = new QSqlQueryModel;
	QString model = "select * from ";	 

   	if( FS-4<=0 )
   	{
   		if( FS-4!=0)
   		{
   			model = model + WordLibBox->currentText() + " where Familiar =" + QString::number(FS);
  		}
  		else
  		{
  			model = model + WordLibBox->currentText();
 		}
  	}
  	else
  	{
		model = model + WordLibBox->currentText() + " where Familiar !=" + QString::number(FS-4);
 	}
 	LibModel->setQuery(model);
 	
 	CheckEnd = LibModel->rowCount();
 	
 	return LibModel; 	
}
开发者ID:san0xff,项目名称:lazyword,代码行数:31,代码来源:LazyWord.cpp

示例10: checkExists

bool DataBank::checkExists(unsigned int i)
{
    bool bit = false;
    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 j = 0; j < model.rowCount(); ++j){
        QString name = model.record(j).value("name").toString();
        if((unsigned int)name.mid(5,2).toInt(&ok ,10) == i){
            bit = true;
        }
    }

    database.close();
    return bit;
}
开发者ID:taiyuankejizhu,项目名称:SparkZNC,代码行数:25,代码来源:databank.cpp

示例11: getDistinctFromDB

QVector<InternalPaymentItem *> ClinicInternalPayment::selectFromDB(QDate startDate, QDate endDate)
{
    QVector<InternalPaymentItem *> result;
    if(myDB::connectDB())
    {
        QString strClumn = "ChinicReceipt";
        QVector<QString> Receipt = getDistinctFromDB(strClumn , strClinicChargeDetails);

        QSqlQueryModel *sqlModel = new QSqlTableModel;
        for(int i=0;i<Receipt.size();i++)
        {
            InternalPaymentItem *item = new InternalPaymentItem;
            item->m_strName = Receipt.at(i);

            QString startTime = startDate.toString("yyyy-MM-dd") + "T00:00:00";
            QString endTime = endDate.toString("yyyy-MM-dd") + "T23:59:59";
            sqlModel->setQuery("Select * from " + strClinicChargeDetails +
                               " where "+ strClumn + "= \'" + item->m_strName +
                               "\' and chargeid in (select id from cliniccharge where time between \'" +
                               startTime +
                               "\' and \'" +
                               endTime + "\')");
            for(int j = 0;j<sqlModel->rowCount();j++)
            {
                int nCount = sqlModel->record(j).value("ChargeItemCount").toInt();
                double nPrice = sqlModel->record(j).value("ChargeItemPrice").toDouble();
                item->m_dDueIncome += nCount*nPrice;
            }
            result.append(item);
        }
    }

    return result;
}
开发者ID:xuebeibei,项目名称:HIS,代码行数:34,代码来源:clinicinternalpayment.cpp

示例12: populateCerealField

void DetalleCompraVenta::populateCerealField()
{
    QSqlQueryModel cereal;
    cereal.setQuery("SELECT cereal,id FROM cereales");
    for(int i=0; i < cereal.rowCount(); i++)
    {
        //ui->grano->addItem( cereal.data(cereal.index(i,0)).toString(), QVariant( cereal.data(cereal.index(i,1)).toInt()));
    }
}
开发者ID:rockols,项目名称:acopio,代码行数:9,代码来源:detallecompraventa.cpp

示例13: information

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // подключаемся к БД
    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("postgres");
    db.setUserName("postgres");
    db.setPassword("12321");
    if(!db.open())
    {
        QMessageBox::critical(
                    this,
                    tr("Ошибка подключения к БД"),
                    tr("Не удалось подключиться к БД.\n")
                        + db.lastError().text()
                    );
        return;
    }
    else QMessageBox::information(
                this,
                tr("Всё огонь"),
                tr("Успешное подключение к БД.")
                );

    // создаём модель запроса и выполняем его в ней
    QSqlQueryModel *model = new QSqlQueryModel;
    // запрашиваем имена полей таблицы
    model->setQuery("SELECT column_name FROM information_schema.columns "
                    "WHERE information_schema.columns.table_name = "
                    "'ВАША_ТАБЛИЦА';");

    // создаём модель для комбо-бокса по числу строк из модели запроса
    QStandardItemModel *model4combo =
            new QStandardItemModel(model->rowCount(), 1, this);

    // переносим данные из модели запроса в модель для комбо-бокса
    QModelIndex index; // индекс для навигации по модели запроса
    for (int i = 0; i < model4combo->rowCount(); i++)
    {
        index = model->index(i, 0, QModelIndex());
        // создаём элемент для добавления в модель комбо-бокса
        QStandardItem* item = new QStandardItem(model->data(index).toString());
        // расставляем флаги, чтобы каждый элемент модели бы чекуемым
        item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
        item->setData(Qt::Checked, Qt::CheckStateRole);
        // добавляем элемент в модель для комбо-бокса
        model4combo->setItem(i, 0, item);
    }

    // назначаем комбо-боксу нашу модель
    ui->comboBox->setModel(model4combo);
}
开发者ID:retifrav,项目名称:scratches,代码行数:56,代码来源:mainwindow.cpp

示例14: 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()));
    }
}
开发者ID:rockols,项目名称:acopio,代码行数:10,代码来源:detallecompraventa.cpp

示例15: v

Manager::Manager(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Manager)
{
    ui->setupUi(this);

    progressBar = new QProgressBar(ui->statusbar);
    progressBar->setMaximumSize(250,40);
    ui->statusbar->addPermanentWidget(progressBar);

    setTabOrder(ui->lineEdit_band_name, ui->lineEdit_Album);
    setTabOrder(ui->lineEdit_Album, ui->lineEdit_price_min);
    setTabOrder(ui->lineEdit_price_min, ui->lineEdit_price_max);

    Database conn;
    QSqlQueryModel * model = new QSqlQueryModel();

    conn.connOpen("Inventory");
    QSqlQuery * qry = new QSqlQuery(conn.mydb);

    qry->prepare("SELECT * from Inventory");
    qry->exec();
    while(qry->next())
    {
        newCatNum = qry->value(12).toInt();
    }
    ++newCatNum;

    model->setQuery(*qry);
    ui->tableView_Master->setModel(model);

    Database conn1;

    conn1.connOpen("Inventory");
    QSqlQuery * qry1 = new QSqlQuery(conn1.mydb);

    ui->comboBox_Type->addItem("Select a Type");

    qry1->prepare("SELECT DISTINCT Type from Inventory");
    qry1->exec();
    while(qry1->next())
    {
        ui->comboBox_Type->addItem(qry1->value(0).toString());
    }

    QModelIndex index = ui->comboBox_Type->model()->index(0, 0);
    QVariant v(0);
    ui->comboBox_Type->model()->setData(index, v, Qt::UserRole - 1);

    conn.connClose();
    conn1.connClose();

    qDebug() << (model->rowCount());
}
开发者ID:anava014,项目名称:Demented---Windows-GUI-Application,代码行数:54,代码来源:manager.cpp


注:本文中的QSqlQueryModel::rowCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。