Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt 6.6.1 编译过程 (How do I compile it in qt 6.6.1 on Windows, Mingw 11.2.0) #38

Open
CHN-STUDENT opened this issue Jan 26, 2024 · 0 comments

Comments

@CHN-STUDENT
Copy link

@thecodemonkey86 thanks to thecodemonkey86, I compile it in qt 6.6.1 successfully, this is my note.Hope can help you.
By the way, i install mysql8 on my windows 11.

  1. Copy mysql lib path and head path to other dir. Because I got some errors like Permission denied or No such file or directory ,so change it in a simple path.
    复制 mysql 头文件和 lib 库到一个简单目录,避免玄学问题。
C:\Program Files\MySQL\MySQL Server 8.0\include -> D:\mysql\include 
C:\Program Files\MySQL\MySQL Server 8.0\lib -> D:\mysql\lib
  1. Build qmysql.dll using cmake gui and cmake cmake --build build --target install.
    使用 cmake-gui 和 cmake 命令 cmake --build build --target install 构建 qmysql.dll。
    image
    image
  2. Copy driver from C:\Program Files (x86)\QSQLiteDriverPlugins\plugins\sqldrivers to D:\Qt\6.6.1\mingw_64\plugins\sqldrivers
    复制 qsqlmysql 驱动到 qt 插件目录。
    image
  3. Try to print all QSqlDatabase::drivers , But i found it is empty, and using ChatGpt, it tells me i need set plugins path.
    打印看看是否有 mysql 驱动,如果找不到,把目录加进去,
QCoreApplication::addLibraryPath("D:/Qt/6.6.1/mingw_64/plugins");
qDebug() << QSqlDatabase::drivers();

image
6. Copy qsqlmysql.dll to project build path like build-opcTrans-Desktop_Qt_6_6_1_MinGW_64_bit-Release\sqldrivers.
复制qsqlmysql.dll 到 exe 输出目录下sqldrivers目录,没有建一个。
image
7. Copy libmysql.dll to project build path like build-opcTrans-Desktop_Qt_6_6_1_MinGW_64_bit-Release.
复制libmysql.dll 到 exe 输出目录下。
image
8. Try to connect db.
然后就可以试试了。

 QCoreApplication::addLibraryPath("D:/Qt/6.6.1/mingw_64/plugins");
    qDebug() << QSqlDatabase::drivers();
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("ip");
    db.setPort(3306);
    db.setDatabaseName("dbname");
    db.setUserName("user");
    db.setPassword("password");
    bool ok = db.open();
    if (ok){
        qDebug() << "OK";
    }
    else {
        QSqlError error = db.lastError();
        qDebug()<<"error open database because"<< error.text();
    }

Here are libmysql.dll。我自己编译的文件。
libmysql.zip
qsqlmysql.dll
sqldrivers.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant