Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSqlError(-1, "Driver not loaded", "Driver not loaded")



  • Hi,

    I am trying to connect to a sql database for the first time and I'm having some trouble. I don't know much about sql or qt, so I've been adapting my code from someone who worked on this project before me in visual studio. I cannot seem to over my database, and I think its because I'm not using the correct driver. Here's my code:

    qDebug()<<QSqlDatabase::drivers();

    QSqlDatabase db;
    db.addDatabase("QODBC3");
    db.setHostName("localhost");
    db.setDatabaseName("databaseName");
    db.setUserName("name");
    db.setPassword("pa$$");

    bool ok = db.open();
    if (ok == false) qDebug() << db.lastError();

    The first debug statement returns all valid drivers ("QSQLITE", "QODBC", "QODBC3") but none of those do anything, i still get the driver not loaded error when I try to open the database.

    One last thing, I got most of my data (username, password, ect) from the code I've been copying, but that code uses driver = get_driver_instance(); which is totally unknown to me.

    Thanks in advance for any help,


Log in to reply