Hi there guys,

I have a bit of a problem here. I have the following code:

Implementation:
Qt Code:
  1. //This function will open the database file (which should lie in the path indicated by the user)
  2. void mainwindow::loaddatabase() {
  3. //This pretty much says that the database will be of SQLite type, and opens it up from a given path
  4. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  5. db.setDatabaseName(path);
  6.  
  7. //This "if" shows up a messagebox in case the program cannot load a given database
  8. if (!db.open()) {
  9. QMessageBox::warning(0, qApp->tr("Cannot open database"),
  10. qApp->tr("Unable to establish a database connection.\n"
  11. "This program requires a database to operate. Please contact "
  12. "the developer of this software for more information on "
  13. "how to use it.\n\n"), QMessageBox::Ok);
  14. }
  15.  
  16. //Note: "medadmin" is the name of the table in the SQLite3 database
  17. model->setTable ("medadmin");
  18. model->select();
  19. ...
  20. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. //this makes the openFile dialog get path of the database file and then invocate loaddatabase with such path as the parameter
  2. void mainwindow::openfile() {
  3.  
  4. path = QFileDialog::getOpenFileName(this,
  5. tr("Open Database File"), "/Users", tr("SQLite Database File (*.db)"));
  6. if (!path.isEmpty()){
  7. loaddatabase();
  8. }
  9. }
To copy to clipboard, switch view to plain text mode 

This was declared in the header:

Qt Code:
  1. class mainwindow : public QMainWindow
  2. {
  3. //declaring the path variable
  4. QString path;
  5. ...
  6. }
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