Solved Error compiling libqsqlmysql.so ( On Ubuntu)
-
Hi all
i am writing a stupid thread that needs to read some settings from a mysql database. Here i have snippet of code:int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("mydb"); db.setUserName("root"); db.setPassword("root"); db.setHostName("localhost:50000"); if(db.open()) { qDebug() << "ok"; } else { qDebug() << "ko"; } return a.exec(); }
This code prints "ko". The very strange thing is that replacing QMYSQL with QSQLITE the database connection is correctly opened! I was wondering if the problem is on the connector. I have made ldd on libqsqlmysql.so and this is the output:
~/Qt_5.12/5.12.2/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so linux-vdso.so.1 => (0x00007fffc5fdc000) libQt5Sql.so.5 => /home/cristiano/Qt_5.12/5.12.2/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007fe96e0c5000) libQt5Core.so.5 => /home/cristiano/Qt_5.12/5.12.2/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007fe96d932000) libmysqlclient.so.20 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 (0x00007fe96d2e8000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe96cf65000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe96cb9b000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe96c97e000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe96c674000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe96c45e000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe96c244000) libicui18n.so.56 => /home/cristiano/Qt_5.12/5.12.2/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007fe96bdaa000) libicuuc.so.56 => /home/cristiano/Qt_5.12/5.12.2/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007fe96b9f2000) libicudata.so.56 => /home/cristiano/Qt_5.12/5.12.2/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007fe96a00f000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe969e0a000) libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe969c08000) libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe9698f7000) /lib64/ld-linux-x86-64.so.2 (0x000055668565a000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe969686000)
As you can see, all the dependencies are respected.
What am i doing wrong?
i think that i am making a very stupid error.Sorry for wasting you all time.
Thanks
Cristiano
-
@CristianoNarcisiVidex What does https://doc.qt.io/qt-5/qsqldatabase.html#lastError say (after open())?
-
db.setHostName("localhost:50000");
The very strange thing is that replacing QMYSQL with QSQLITE the database connection is correctly opened!So you have both QMYSQL and QSQLITE listening on the same port number?? Or, you have QSQLITE listening there, hence it's wrong for QMYSQL?
-
Re: Error compiling libqsqlmusql.so ( On Ubuntu)
Hi All
As i have predicted before, there was a very stupid error! It seems that
db.setHostName("localhost:50000");
is not valid using QMYSQL, but is valid for QSQLITE
i have replaced it with
db.setPort(50000); db.setHostName("localhost");
And now i can connect to the db using the QMYSQL connector
Sorry for bothering you!
Thanks
Cristiano