本文整理汇总了C++中QSqlRecord类的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRecord类的具体用法?C++ QSqlRecord怎么用?C++ QSqlRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addTreatments
bool PatientAccounter::addTreatments(QString& Document)
{
bool treated = false;
double sum = 0;
//Iterate over all Treatments
for (int i = 0; i < m_treats.rowCount(); i++)
{
QSqlRecord treatment = m_treats.record(i);
if (treatment.value(Accounted).toInt() == 1 ||
treatment.value(Accounted).toInt() == 2)
{
continue;
}
treatment.setValue(QString("accounted"), 2);
m_treats.setRecord(i, treatment);
treated = true;
if (!m_treats.submit())
{
std::cerr << "Failed to update Treatment! \n";
}
Document.append(addTreatmentRow(treatment, sum));
}
//Create the Final Sum Row
QString sumString;
sumString.setNum(sum, 'f', 2);
Document.append("{\\b Endsumme: ");
Document.append(sumString + " Euro \\qr \\par} \\par");
return treated;
}
示例2: on_roomAdd_clicked
void RoomSetting::on_roomAdd_clicked()
{
if(1 == model_build->rowCount()){
ToolUtil::ShowMessageBoxError("请先设置楼栋,如果只有一栋楼,请设置名称",this);
return;
}
int curRow=ui->table1->currentIndex().row();
if(-1 == curRow || 0 == curRow){
ToolUtil::ShowMessageBoxError("请先选中要添加到的楼栋",this);
return;
}
QString buil_no = model_build->record(curRow).field("build_no").value().toString();
QString room_no = ToolUtil::ShowInputDlg("请输入房间名称",this).trimmed();
if(room_no.length() > 10 || room_no.length() <= 0){
ToolUtil::ShowMessageBoxError("您输入的名称不符要求",this);
return;
}
QSqlRecord record = model_room->record();
record.setValue("build_no",buil_no);
record.setValue("room_no",room_no);
model_room->insertRecord(0,record);
model_room->submit();
}
示例3: playlistTableModel
void SetlogFeature::buildPlaylistList() {
m_playlistList.clear();
// Setup the sidebar playlist model
QSqlTableModel playlistTableModel(this, m_pTrackCollection->getDatabase());
playlistTableModel.setTable("Playlists");
playlistTableModel.setFilter("hidden=2"); // PLHT_SET_LOG
playlistTableModel.setSort(playlistTableModel.fieldIndex("id"),
Qt::AscendingOrder);
playlistTableModel.select();
while (playlistTableModel.canFetchMore()) {
playlistTableModel.fetchMore();
}
QSqlRecord record = playlistTableModel.record();
int nameColumn = record.indexOf("name");
int idColumn = record.indexOf("id");
for (int row = 0; row < playlistTableModel.rowCount(); ++row) {
int id = playlistTableModel.data(
playlistTableModel.index(row, idColumn)).toInt();
QString name = playlistTableModel.data(
playlistTableModel.index(row, nameColumn)).toString();
m_playlistList.append(qMakePair(id, name));
}
}
示例4: QWizard
ActivityWizard::ActivityWizard(QSqlRecord &record, QWidget *parent)
: QWizard(parent), mRecord(record) {
auto firstPage = new ActivityWizardNameAndTypePage(this);
firstPage->setActivityId(record.value("ID").toULongLong());
setPage(0, firstPage);
setPage(1, new ActivityWizardFixedDatePage(this));
setPage(2, new ActivityWizardRepetitiveDatesPage(this));
setPage(3, new ActivityWizardListsSelectionPage(this));
setPage(4, new ActivityWizardRoomsSelectionPage(this));
setMinimumSize(640, 480);
button(QWizard::BackButton)->setText(tr("Back"));
button(QWizard::NextButton)->setText(tr("Next"));
button(QWizard::CancelButton)->setText(tr("Cancel"));
button(QWizard::FinishButton)->setText(tr("Finish"));
}
示例5: showMetaData
void Browser::showMetaData(const QString &t)
{
QSqlRecord rec = connectionWidget->currentDatabase().record(t);
QStandardItemModel *model = new QStandardItemModel(table);
model->insertRows(0, rec.count());
model->insertColumns(0, 7);
model->setHeaderData(0, Qt::Horizontal, "Fieldname");
model->setHeaderData(1, Qt::Horizontal, "Type");
model->setHeaderData(2, Qt::Horizontal, "Length");
model->setHeaderData(3, Qt::Horizontal, "Precision");
model->setHeaderData(4, Qt::Horizontal, "Required");
model->setHeaderData(5, Qt::Horizontal, "AutoValue");
model->setHeaderData(6, Qt::Horizontal, "DefaultValue");
for (int i = 0; i < rec.count(); ++i) {
QSqlField fld = rec.field(i);
model->setData(model->index(i, 0), fld.name());
model->setData(model->index(i, 1), fld.typeID() == -1
? QString(QVariant::typeToName(fld.type()))
: QString("%1 (%2)").arg(QVariant::typeToName(fld.type())).arg(fld.typeID()));
model->setData(model->index(i, 2), fld.length());
model->setData(model->index(i, 3), fld.precision());
model->setData(model->index(i, 4), fld.requiredStatus() == -1 ? QVariant("?")
: QVariant(bool(fld.requiredStatus())));
model->setData(model->index(i, 5), fld.isAutoValue());
model->setData(model->index(i, 6), fld.defaultValue());
}
table->setModel(model);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
updateActions();
}
示例6: fillMaterialBuffer
void MaterialSaverDB::fillMaterialBuffer( QSqlRecord &rec, StockMaterial *mat, bool isNew )
{
if( ! ( mat ) ) return;
rec.setValue( "chapterID", mat->chapter() );
rec.setValue( "material", mat->name() );
rec.setValue( "unitID", mat->getUnit().id() );
rec.setValue( "perPack", mat->getAmountPerPack() );
rec.setValue( "priceIn", mat->purchPrice().toDouble() );
rec.setValue( "priceOut", mat->salesPrice().toDouble() );
QString dtString = KraftDB::self()->currentTimeStamp();
if( isNew ) {
rec.setValue( "enterDate", dtString);
}
rec.setValue("modifyDate", dtString );
}
示例7: QString
bool InternalModule::createPcs(QSqlQuery& db) {
QString query = QString("Select * from projectedcsy");
if ( db.exec(query)) {
std::vector<Resource> items;
while (db.next()) {
QSqlRecord rec = db.record();
QString code = rec.value("code").toString();
QString name = rec.value("name").toString();
QString url = QString("ilwis://tables/projectedcsy?code=%1").arg(code);
Resource resource(url, itCONVENTIONALCOORDSYSTEM);
resource.code(code);
resource.name(name, false);
resource["wkt"] = name;
resource.addContainer(QUrl("ilwis://system"));
items.push_back(resource);
}
bool ok = mastercatalog()->addItems(items);
return ok;
} else {
kernel()->issues()->logSql(db.lastError());
}
return false;
}
示例8: on_buildMod_clicked
void RoomSetting::on_buildMod_clicked()
{
int row = ui->table1->currentIndex().row();
if(-1 == row){
ToolUtil::ShowMessageBoxInfo("请先选中需要修改的项",this);
return;
}
QString build_no = ToolUtil::ShowInputDlg("请输入楼栋名称",this).trimmed();
if(NULL == build_no){
return;
}
if(build_no.length() > 10 || build_no.length() <= 0){
ToolUtil::ShowMessageBoxError("您输入的名称不符要求",this);
return;
}
if(model_room->rowCount() > 0){
if(ToolUtil::ShowMessageBoxQuesion("修改楼栋名称将会修改到房间信息?",this)){
for(int i=model_room->rowCount(); i >= 0; i--){
QSqlRecord room_record = model_room->record(i);
room_record.setValue("build_no",build_no);
model_room->setRecord(i,room_record);
}
model_room->submitAll();
QSqlRecord record = model_build->record(row);
record.setValue("build_no",build_no);
model_build->setRecord(row,record);
model_build->submit();
}
}else{
QSqlRecord record = model_build->record(row);
record.setValue("build_no",build_no);
model_build->setRecord(row,record);
model_build->submit();
}
}
示例9: results
QVariantList Query::results()
{
QVariantList results;
QSqlRecord r = query.record();
while(query.next())
{
QVariantMap prop;
///iterate on the properties:
for(int i=0; i< r.count(); i++)
{
QString name = r.fieldName(i);
QVariant val = query.value(i);
prop[name] = val;
}
results << prop;
}
return results;
}
示例10: record
QSqlRecord QTDSDriver::record(const QString& tablename) const
{
QSqlRecord info;
if (!isOpen())
return info;
QSqlQuery t(createResult());
t.setForwardOnly(true);
QString table = tablename;
if (isIdentifierEscaped(table, QSqlDriver::TableName))
table = stripDelimiters(table, QSqlDriver::TableName);
QString stmt (QLatin1String("select name, type, length, prec from syscolumns "
"where id = (select id from sysobjects where name = '%1')"));
t.exec(stmt.arg(table));
while (t.next()) {
QSqlField f(t.value(0).toString().simplified(), qDecodeTDSType(t.value(1).toInt()));
f.setLength(t.value(2).toInt());
f.setPrecision(t.value(3).toInt());
f.setSqlType(t.value(1).toInt());
info.append(f);
}
return info;
}
示例11: QxSqlResult
void QxSqlQuery::fetchSqlResult(QSqlQuery & query)
{
bool bCheckRecord = true;
m_pSqlResult.reset(new QxSqlResult());
if (query.size() > 0) { m_pSqlResult->values.reserve(query.size()); }
while (query.next())
{
if (bCheckRecord)
{
bCheckRecord = false;
QSqlRecord record = query.record();
m_pSqlResult->positionByKey.reserve(record.count());
for (int i = 0; i < record.count(); i++)
{ m_pSqlResult->positionByKey.insert(record.fieldName(i), i); }
qAssert(record.count() == m_pSqlResult->positionByKey.count());
}
QVector<QVariant> lst;
lst.reserve(m_pSqlResult->positionByKey.count());
for (long j = 0; j < m_pSqlResult->positionByKey.count(); j++)
{ lst.append(query.value(j)); }
qAssert(lst.count() == m_pSqlResult->positionByKey.count());
m_pSqlResult->values.append(lst);
}
}
示例12: on_ownerOKButton_clicked
void Settings::on_ownerOKButton_clicked()
{
int ind = 0;
if(ui->ownerOKButton->text() == "Добавить")
ownerModel->insertRow(ind);
else
ind = ui->ownerView->currentIndex().row();
QSqlRecord rec = ownerModel->record();
ownerModel->setData(ownerModel->index(ind, rec.indexOf("name")),\
ui->ownerName->text());
ownerModel->setData(ownerModel->index(ind, rec.indexOf("owner")),\
ui->ownerID->text());
if (!ownerModel->submitAll()) {
qDebug() << "Insertion error!";
}
ui->frame->hide();
QModelIndex index= ui->ownerView->currentIndex();
ownerModel->select();
ui->ownerView->setCurrentIndex(index);
ui->ownerID->clear();
ui->ownerName->clear();
}
示例13: getField
QString CacheDatabase::getField(const QString &what, const QString &where, const QString &value)
{
// If same return
if(what == where)
return QString::null;
// Create model
QSqlTableModel* model = new QSqlTableModel;
// Set table
model->setTable(CacheTableName);
// Edit stategy
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
// Set filter
model->setFilter(QString("%1='%2'").arg(where, value));
// Run selection
model->select();
// Get record
QSqlRecord record = model->record(0);
// If not empty
if(!record.isEmpty())
// Get value
return record.value(record.indexOf(what)).toString();
// Return result
return QString::null;
}
示例14: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
dbpath = "technologybasic.db";
ui->setupUi(this);
ui->textBrowser->setFont(QFont("SolaimanLipi",12,300,false));
if(!QFile(dbpath).exists())
{
QMessageBox::warning(this, "Error", "Database not found","Select file");
dbpath = QFileDialog::getOpenFileName(this, "Select Data Base File", QDir::homePath(), "SQLite Database (*.db)");
}
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(dbpath);
db.open();
QSqlQuery query("SELECT `name`, `details` from `terms`");
QSqlRecord record = query.record();
while (query.next())
{
Title << query.value(record.indexOf("name")).toString();
Text << query.value(record.indexOf("details")).toString();
}
QButtonGroup *buttons = new QButtonGroup;
for(int i=0;i<Title.size();i++)
{
ui->listWidget->addItem(Title.at(i));
QPushButton *button = new QPushButton(Title.at(i));
button->setStyleSheet("QPushButton { background-color: green; border-style: inset; border-width: 1px; border-radius: 10px; border-color: white; font: bold 14px; color: white; }");
ui->gridScrollArea->addWidget(button);
buttons->addButton(button);
}
QObject::connect(buttons, SIGNAL(buttonClicked(int)), this, SLOT(buttonClick(int)));
}
示例15: QSqlQuery
/*! Устанавливает запрос, подключается к базе данных, получает данные
и создает древовидную структуру. */
void QstTreeQueryModel::setQuery(const QString& query, const QSqlDatabase &db)
{
_query = QSqlQuery(query, db);
_lastError = _query.lastError();
Q_ASSERT(_query.isActive());
QSqlRecord record = _query.record();
QList<QVariant> rootHeader;
int fieldsCount = record.count();
// Вписываем в шапку все поля.
for (int i = 0; i < fieldsCount; ++i)
rootHeader << record.fieldName(i);
// Если было дерево, удаляем. Создаем новое дерево.
if (_root) delete _root;
_root = new QstTreeItem(rootHeader);
Q_CHECK_PTR(_root);
_createTree();
}