Connect to MYSQL failed in Qt
-
@Christian-Ehrlicher bcuz it give too much error,i rather use official mysql header
Qt6 has alot of stuff doesnt exist.Like web browser
So i rather use the official mysql header and it give less errorThese are the only error:
error: undefined reference to 'mysql_init'
error: undefined reference to 'mysql_real_connect'
error: linker command failed with exit code 1 (use -v to see invocation) clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makefile:73: libPos_x86_64.so] Error 1
Use Qt sql give like 11 error or more/less
-
The SQL module is supported in Qt 6. However the MySQL plugin might not be provided because Oracle changed their licensing.
As for your build issue: -L is for giving path to search, it's -l for stating the name of the library.
-
So the QtSql module has no errors - please stay specific!
else:unix: LIBS += -L$$PWD/lib/libmysql.lib
This is for sure not correct.
-
@Christian-Ehrlicher but qtsql mysql plugin doesnt provided as @SGaist said it,i tried add it by following youtube tutorial,it still doesnt.Lemme try it again and send the error here
-
-
@ELEMENTICY said in Connect to MYSQL failed in Qt:
This is for sure not correct.
oh,how do i fix it?
Re-read my previous answer.
-
No space no "lib" prefix.
It's explained in the documentation
-
@SGaist my current profile code:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibmysql else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibmysqld else:unix: LIBS += -L$$PWD/lib/ -llibmysql
documentation:
LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer
i got this error:
:-1: error: error: cannot find -llibmysql
proof that path exists:
-
@ELEMENTICY said in Connect to MYSQL failed in Qt:
And yea,use qt sql it just give like 11 error
What does this mean?
-
@ELEMENTICY did you read what I wrote ? No "lib" prefix.
-
@SGaist
current code:win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld else:unix: LIBS += -L$$PWD/lib/libmysql
idk if i misunderstanded what u mean,but it still give error ;/
or u mean i have to remove that -L -
@ELEMENTICY said in Connect to MYSQL failed in Qt:
@SGaist
current code:win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld else:unix: LIBS += -L$$PWD/lib/libmysql
idk if i misunderstanded what u mean,but it still give error ;/
or u mean i have to remove that -LYou have to understand what -L and -l each do. I have already explained that before. So please re-read the corresponding answers.
-
@ELEMENTICY said in Connect to MYSQL failed in Qt:
@SGaist and yea i dont know if its because im working on a android app,so it doesnt work
Oracle does not provide pre-built binaries for Android.
-
@SGaist dude,im so tired...
Can you pleaseee write the 3 lines of code for me?
Please... i hope after you see this message,you wont just ignore and think i never hard work on it..But im tired for just add a simple library already...
It will be the BEST help for meMy current code...
win32:CONFIG(release, debug|release): LIBS += $$PWD/lib/ -llibmysql else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/lib/ -llibmysqld else:unix: LIBS += $$PWD/lib/ -llibmysql
Error:
:-1: error: error: cannot open C:/Users/ELEMENT/Documents/PosSystem/Pos/lib/: Permission denied
I opened QT Creator with Administrator,still same...I also tried..
win32:CONFIG(release, debug|release): LIBS += $$PWD/lib/libmysql else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/lib/libmysqld else:unix: LIBS += $$PWD/lib/libmysql
Error:
:-1: error: no such file or directory: 'C:/Users/ELEMENT/Documents/PosSystem/Pos/lib/libmysql' clang++: error: no such file or directory: 'C:/Users/ELEMENT/Documents/PosSystem/Pos/lib/libmysql' make: *** [Makefile:79: libPos_x86_64.so] Error 1
Seems like that one is the wrong way to do without adding -lappreciate it...
-
@SGaist I removed:
win32:CONFIG(release, debug|release): LIBS += $$PWD/lib/ -llibmysql else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/lib/ -llibmysqld else:unix: LIBS += $$PWD/lib/ -llibmysql
And tried only
LIBS += -L"lib" -llibmysql
Still error:
:-1: error: error: cannot find -llibmysql
-
"Drop the lib prefix":
-lmysql
To repeat myself: Oracle does not provide pre-built binaries for Android.
Also, @Christian-Ehrlicher already asked you several times: what exact error did you get with the QtSql module ?
-
@SGaist ok its weird,it now dont give any error.But its EXCELENT!
But it unable to connect to Server
My code:QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("pos"); db.setUserName("root"); if (!db.open()){ ui->error->setText("Oops,Unable to connect to Server!Please contact your Administrator for help."); }
Includes:
#include <QtSql/QSql> #include <QtSql/QSqlDatabase> #include <QtSql/QSqlDriver> #include <QtSql/QSqlQuery>
and i also added sql to Qt in Profile
QT += core gui sql
-
@ELEMENTICY im sure i entered correct server info