[Qt-interest] Design of Qt/DB applications
William Lugg
wlugg at prairienetworks.com
Wed Jan 27 02:37:58 CET 2010
OK, here's what may be a duh question.
I've been trying to study the SQL examples and figure that out, but have
failed. I'm working on an application that will provide a rather elaborate
membership roster for an organization. It is using SQLite for the DB engine
and Qt (obviously) for the GUI. I've build a simple class to handle the
connection of the app to the DB and got the impression from the examples that
I should place a call to the static connection::createConnection() in main.cpp
before I started the app itself. However, after some debugging, I'm
discovering that it looks like I need the createConnection call in each form
and dialog I open that needs access to the DB. Is the correct or am I not
doing the right things in my createConnection code? Here's the code if that
helps...
bool Connection::createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "rlhs_db");
db.setDatabaseName("../database/rlhs_db");
if (db.open())
{
return true;
}
else
{
QMessageBox::critical(0,
qApp->tr( "Cannot open database"),
qApp->tr( "Unable to establish a database connection.\n"
"This application 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;
}
}
Looks a lot like the example code, doesn't it? :o)
Thanks for the help.
----
Bill Lugg
Milstar Software Support
Peterson AFB, CO
No Micro$oft products were used to create this email.
God rules and if He needed a computer it would run Linux!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100126/82344f7b/attachment.html
More information about the Qt-interest-old
mailing list