Table Details
Database : SQLITE
Table Name : ConfigTable
Fields :
FormId Numeric
FormName Text
FormHeight Numeric
FormWidth Numeric
ConfigTable location : E:\Bala\Ramana\DynamicForm\DynaBase
connection.h
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
static bool createConnection()
{
//db.setDatabaseName(":memory:");
//db.setDatabaseName("e:/BALA/hirola");
db.setDatabaseName("e:/BALA/Ramana/DynamicForm/DynaBase");
if (!db.open()) {
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
return false;
}
return true;
}
#endif
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
//db.setDatabaseName(":memory:");
//db.setDatabaseName("e:/BALA/hirola");
db.setDatabaseName("e:/BALA/Ramana/DynamicForm/DynaBase");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
return true;
}
#endif
To copy to clipboard, switch view to plain text mode
DynamicTable.Cpp
#include <QApplication>
#include <QGridLayout>
#include <QPushButton>
#include <QProcess>
#include "Connection.h"
#include <QtCore/QVariant>
int main(int argc, char *argv[])
{
QObject::connect(ClickButton,
SIGNAL(clicked
()),
&app,
SLOT(quit
()));
if(!createConnection())
return 1;
q.exec("SELECT * FROM ConfigTable");
q.next();
win1->setWindowTitle("Window1");
win1->setFixedHeight(q.value(2).toInt()); //FormHeight
win1->setFixedWidth(q.value(3).toInt()); //FormWidth
layout->addWidget(ClickButton,0,0);
layout->addWidget(CancelButton,0,2);
win1->setLayout(layout);
win1->show();
return app.exec();
}
#include <QApplication>
#include <QGridLayout>
#include <QPushButton>
#include <QProcess>
#include "Connection.h"
#include <QtCore/QVariant>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *win1 = new QWidget;
QGridLayout *layout = new QGridLayout;
QPushButton *ClickButton=new QPushButton("Click");
QPushButton *CancelButton=new QPushButton("Cancel");
QObject::connect(ClickButton,SIGNAL(clicked()),&app,SLOT(quit()));
if(!createConnection())
return 1;
QSqlQuery q;
q.exec("SELECT * FROM ConfigTable");
QString salary;
q.next();
win1->setWindowTitle("Window1");
win1->setFixedHeight(q.value(2).toInt()); //FormHeight
win1->setFixedWidth(q.value(3).toInt()); //FormWidth
layout->addWidget(ClickButton,0,0);
layout->addWidget(CancelButton,0,2);
win1->setLayout(layout);
win1->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
This is working fine for ONE ROW, ONE WINDOW.
how to create n windows, if n rows are in configtable.
Thnks
Bala
Bookmarks