Unable to connect remotely to MySQL database (able via console)



  • Dear all,

    I need your help to solve the following problem:

    1. Database (MySQL) on (Ubuntu) server.
    2. Qt desktop application can connect from development machine (Ubuntu) to database on server and fetch data when both machines are on the local network.
    3. If trying to connect from development machine from outside local network (say at work) then it fails to fetch data and also shows no error. Unable to determine what the exact problem is.
    4. Connecting outside local network via MySQL console works. I can see the tables, etc.

    FYI, this is how I can connect remotely to the database:

    @mysql -hhostname.com -uusr -pmypw@

    This is the code I'm using to connect to the database from within Qt:

    @//--- define the database connection ---
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("hostname.com"); // host
    db.setPort(3306); // not really necessary anymore, port is correct
    db.setDatabaseName("mydb"); // database
    db.setUserName("usr"); // user
    db.setPassword("mypw"); // password

    //--- attempt to open it ---
    bool ok = db.open();

    qDebug() << db.lastError().text();@

    I was assuming that the db.lastError().text() would provide me with info on what is wrong but nothing happens. It just stops responding (window goes dark) and then comes back but no data is fetched.

    Because it is possible to remotely connect via the console I must be doing something wrong within Qt. Can someone tell me how I can troubleshoot this problem? I'm assuming that Qt can connect remotely to MySQL databases?

    Thanks,
    RD



  • Sorry, after some more testing I found out that I was editing a file that was not being compiled. I'm working on a machine that has partitions for both Windows and Ubuntu and has Qt on both). Both partitions have folders in which I develop this application. I copied the folder from the Windows partition to the Ubuntu partition but to a new location. So I had 2 folders in the Ubuntu partition with the same names and the same project name but slightly different files. Editing files from the new location had no effect as Qt was compiling the files in the original location (still wondering how this works).

    But the good news is that it all works now as it should (I can connect remotely) so I can continue with the application.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.