コード例 #1
0
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);
}
コード例 #2
0
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();
}
コード例 #3
0
ファイル: sqldatabase.cpp プロジェクト: 2gis/2gisqt5android
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));
        }
    }
}