Hi there guys,
I have a bit of a problem here. I have the following code:
Implementation:
//This function will open the database file (which should lie in the path indicated by the user)
void mainwindow::loaddatabase() {
//This pretty much says that the database will be of SQLite type, and opens it up from a given path
db.setDatabaseName(path);
//This "if" shows up a messagebox in case the program cannot load a given database
if (!db.open()) {
QMessageBox::warning(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This program requires a database to operate. Please contact "
"the developer of this software for more information on "
}
//Note: "medadmin" is the name of the table in the SQLite3 database
model->setTable ("medadmin");
model->select();
...
}
//This function will open the database file (which should lie in the path indicated by the user)
void mainwindow::loaddatabase() {
//This pretty much says that the database will be of SQLite type, and opens it up from a given path
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(path);
//This "if" shows up a messagebox in case the program cannot load a given database
if (!db.open()) {
QMessageBox::warning(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This program requires a database to operate. Please contact "
"the developer of this software for more information on "
"how to use it.\n\n"), QMessageBox::Ok);
}
//Note: "medadmin" is the name of the table in the SQLite3 database
model->setTable ("medadmin");
model->select();
...
}
To copy to clipboard, switch view to plain text mode
//this makes the openFile dialog get path of the database file and then invocate loaddatabase with such path as the parameter
void mainwindow::openfile() {
tr("Open Database File"), "/Users", tr("SQLite Database File (*.db)"));
if (!path.isEmpty()){
loaddatabase();
}
}
//this makes the openFile dialog get path of the database file and then invocate loaddatabase with such path as the parameter
void mainwindow::openfile() {
path = QFileDialog::getOpenFileName(this,
tr("Open Database File"), "/Users", tr("SQLite Database File (*.db)"));
if (!path.isEmpty()){
loaddatabase();
}
}
To copy to clipboard, switch view to plain text mode
This was declared in the header:
{
//declaring the path variable
...
}
class mainwindow : public QMainWindow
{
//declaring the path variable
QString path;
...
}
To copy to clipboard, switch view to plain text mode
... And it doesn't work! whenever test the program and select a open a .db file he does nothing! I believe that the problem might be associated with the QString path.
Any code with be greatly appreciated 
Thanks in advance
Bookmarks