0

I have given up on trying to configure the MYSQL driver for the Qt 5.0 library, I am going to use the only driver currently available to me - "QSQLITE".

I have been trying to get this working for quite some time and have tried everything mentioned in similar posts: Select from SQLite with Qt

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName(SQL_SERVER);
db.setPort(SQL_PORT);
db.setDatabaseName(SQL_DATABASE);
db.setUserName(SQL_USER);
db.setPassword(SQL_PASS);
bool dbSuccess = db.open();
QList<QString> deviceNames;
QString deviceName;
qDebug() << db;
if(dbSuccess){
    QSqlQuery query;
    qWarning("We made it into the DB");
    query.exec("SELECT device_name FROM tbl_device");
    while (query.next() ){
        qDebug() << query.value(1).toString();
       // deviceNames.append(deviceName);
        //qDebug() << "Test: "<< deviceName;
    }
}
else if(!db.open()){
    qWarning("Database failed to load!");
}

Where SQL_Server = 192.168.1.100

I get the following qDebug output from the application:

QSqlDatabase(driver=""QSQLITE"", database=""homelogic"", host=""hendrenserver"", port=3306, user=""homelogic"",      open=true) 
We made it into the DB

The output suggests that the database connection is valid, however if I change the servername to something completely false such as "xlkcjox" or other random keys - I get the same output. What am I missing here? I feel like this should be relatively easy.

Please advise!

2 Answers 2

2

When using the sqlite driver for qt, the database name is a file on your disc, regardless of the host name. This is how sqlite works. It needs no host just a filename.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay I was confused with PHP where I use sqli_ACTION, in which case you still have to setup the connection to the database.
To connect to an external SQL server, I must configure the SQL driver correct?
0

I am revisiting this question to share a very helpful link that I came across today. I reached a solution using Qt 4.8.4 and QODBC driver. Due to a need to use QSerialPort and project bugs, I updated to 5.0.1 today. When working on rebuilding my ODBC plugin, I found this link: http://seppemagiels.com/blog/create-mysql-driver-qt5-windows. Within 20 minutes I had what I originally wanted, the QMYSQL driver, working. I hope this helps others!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.