Hello everybody!

I have written a program that needs to connect to a mysql db installed on one of the computers in the network. All others computers in the network running the program should be able to connect to the db.

I have a script that connect to the server, it looks like this:

Qt Code:
  1. #ifndef CONNECTION_H
  2. #define CONNECTION_H
  3.  
  4. #include <QMessageBox>
  5. #include <QSqlDatabase>
  6. #include <QSqlError>
  7. #include <QSqlQuery>
  8. #include <QFile>
  9. #include <QTextStream>
  10. #include <QString>
  11.  
  12. static bool createConnection()
  13. {
  14. QFile file;
  15. file.setFileName("connection.txt");
  16. if (!file.open(QFile::ReadOnly| QFile::Text)) {
  17. QMessageBox::critical(0, qApp->tr("Error"),
  18. qApp->tr("Cannot open connection file."
  19. "Click Cancel to exit."), QMessageBox::Cancel);
  20. return false;
  21. }
  22.  
  23. QTextStream in(&file);
  24.  
  25. QString DatabaseName = in.readLine();
  26. QString UserName = in.readLine();
  27. QString Password = in.readLine();
  28. QString HostName = in.readLine();
  29.  
  30.  
  31. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  32. //db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
  33. db.setPort (3306);
  34. db.setDatabaseName( DatabaseName );
  35. db.setUserName( UserName );
  36. db.setPassword( Password );
  37. db.setHostName( HostName );
  38.  
  39. if (!db.open()) {
  40. QMessageBox::critical(0, qApp->tr("Cannot open database"),
  41. qApp->tr("Unable to establish a database connection."
  42. "Click Cancel to exit."), QMessageBox::Cancel);
  43. return false;
  44. }
  45.  
  46. return true;
  47. }
  48.  
  49. #endif
To copy to clipboard, switch view to plain text mode 

The program works when running on the computer where MySQL is installed but fails to connect when running on all the computers in the network.

I am using the ip address of the MySQL server as hostname.

Hope that someone could help me out in this.

Thanks in advance!