void cycleScrDialog::on_pushButton_clicked()
{
// create new database
dbName
= QString(QApplication::applicationDirPath()).
append("/I-" + sDate.
toString("MMyyyy") + ".db");
m4db.setDatabaseName(dbName);
if (!QFile::exists(dbName
)) {
mydb.open();
query.exec("create table c1(ID int primary key unique, "
"StartTime QString, StopTime QString)");
mydb.close();
}
if (!mydb.open())
{
QMessageBox::warning(this, tr
("Unable to open database"), tr
("An error occurred while " "opening the connection: ") + m4db.lastError().text());
return;
}
else
{
query.exec("PRAGMA synchronous = OFF");
model->setTable("c1");
model->select();
model->insertRow(0);
model->setData(model->index(0, 1), String(qdatetime.toString(Qt::ISODate)));
model->setData(model->index(0, 2), String(qdatetime.toString(Qt::ISODate)));
model->submitAll();
}
saveIni();
model->setTable("c1");
model->filter();
model->select();
}
void cycleScrDialog::timer1000Event()
{
model->setTable("c1");
model->select();
model->insertRow(0);
model->setData(model->index(0, 1), String(qdatetime.toString(Qt::ISODate)));
model->setData(model->index(0, 2), String(qdatetime.toString(Qt::ISODate)));
model->submitAll();
}
void cycleScrDialog::on_pushButton_clicked()
{
// create new database
QDate sDate = QDate::currentDate();
QString dbName;
dbName = QString(QApplication::applicationDirPath()).append("/I-" + sDate.toString("MMyyyy") + ".db");
m4db = QSqlDatabase::addDatabase("QSQLITE");
m4db.setDatabaseName(dbName);
if (!QFile::exists(dbName))
{
mydb.open();
QSqlQuery query;
query.exec("create table c1(ID int primary key unique, "
"StartTime QString, StopTime QString)");
mydb.close();
}
if (!mydb.open())
{
QMessageBox::warning(this, tr("Unable to open database"), tr("An error occurred while "
"opening the connection: ") + m4db.lastError().text());
return;
}
else
{
QSqlQuery query;
query.exec("PRAGMA synchronous = OFF");
model = new QSqlTableModel(this);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setTable("c1");
model->select();
model->insertRow(0);
model->setData(model->index(0, 1), String(qdatetime.toString(Qt::ISODate)));
model->setData(model->index(0, 2), String(qdatetime.toString(Qt::ISODate)));
model->submitAll();
}
saveIni();
model->setTable("c1");
model->filter();
model->select();
}
void cycleScrDialog::timer1000Event()
{
model->setTable("c1");
model->select();
model->insertRow(0);
model->setData(model->index(0, 1), String(qdatetime.toString(Qt::ISODate)));
model->setData(model->index(0, 2), String(qdatetime.toString(Qt::ISODate)));
model->submitAll();
}
To copy to clipboard, switch view to plain text mode
Bookmarks