Tag: database

  • How to configure Qt 6 for OpenSSL and PostgreSQL on Windows

    I’m posting this for anyone who may need to compile Qt 6 on Windows with support for both OpenSSL and PosgreSQL. Since I spent an hour of my life figuring this out, I figured I’d share it in hopes that it saves someone else the time.

    You can install both OpenSSL and PosgreSQL from the distributed binaries (easy to find). Make sure you adjust the paths as relevant to your setup. I’m following this guide to compile Qt 6. Here is my command for the configure stage:

    D:\Projects\qt6\configure.bat ^
      -opensource ^
      -confirm-license ^
      -developer-build ^
      -openssl-linked ^
      -I "C:/Program Files/OpenSSL-Win64/include" ^
      -L "C:/Program Files/OpenSSL-Win64/lib" ^
      -nomake examples -nomake tests ^
      -- --fresh ^
      -DPostgreSQL_LIBRARY="C:/Program Files/PostgreSQL/17/lib" ^
      -DPostgreSQL_INCLUDE_DIR="C:/Program Files/PostgreSQL/17/include"

    You can then build as normal. You may want to study the configure output closely to make sure the paths were properly picked up. Once you build you can run a simple application to test your results. ChatGPT gave me this for PostgreSQL:

    #include <QSqlDatabase>
    #include <QDebug>
    
    int main() {
        if (QSqlDatabase::isDriverAvailable("QPSQL")) {
            qDebug() << "PostgreSQL driver is available!";
        } else {
            qDebug() << "PostgreSQL driver is NOT available!";
        }
        return 0;
    }

    ChatGPT also provided me with this:

    if (QSslSocket::supportsSsl()) {
        qDebug() << "SSL is supported!";
    } else {
        qDebug() << "SSL is NOT supported!";
    }

    You should, of course, check these suggestions for accuracy.