#define VARIANT_1
{
Q_OBJECT
public:
SomeClass
(QWidget *parent
= 0, Qt
::WFlags flags
= 0){
ui.setupUi(this);
db.setDatabaseName(":memory:");
if (!db.open()) {
return;
}
query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20))");
query.exec("insert into person values(101, 'Danny', 'Young')");
query.exec("insert into person values(102, 'Christine', 'Holand')");
#if defined( VARIANT_1 )
#endif
model.setTable("person");
model.select();
model.
setHeaderData(0, Qt
::Horizontal,
QObject::tr("ID"));
model.
setHeaderData(1, Qt
::Horizontal,
QObject::tr("First name"));
model.
setHeaderData(2, Qt
::Horizontal,
QObject::tr("Last name"));
ui.tableView->setModel(&model);
}
private:
Ui::qhlbClass ui;
#if defined( VARIANT_1 )
#else
#endif
};
#define VARIANT_1
class SomeClass : public QWidget
{
Q_OBJECT
public:
SomeClass(QWidget *parent = 0, Qt::WFlags flags = 0)
{
ui.setupUi(this);
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (!db.open()) {
return;
}
QSqlQuery query;
query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20))");
query.exec("insert into person values(101, 'Danny', 'Young')");
query.exec("insert into person values(102, 'Christine', 'Holand')");
#if defined( VARIANT_1 )
p_model = new QSqlTableModel( );
QSqlTableModel & model = *p_model;
#endif
model.setTable("person");
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
model.select();
model.setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model.setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
model.setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
ui.tableView->setModel(&model);
}
private:
Ui::qhlbClass ui;
QSqlDatabase db;
#if defined( VARIANT_1 )
QSqlTableModel * p_model;
#else
QSqlTableModel model;
#endif
};
To copy to clipboard, switch view to plain text mode
Bookmarks