简体   繁体   中英

get_driver_instance() crashes with Qt

I'm trying to User MySQL Connector/C++ with Qt, and had spent hours pulling my hairs on a problem. Here's a SIMPLE code to test out the connection:

int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
cout << "aa" << endl;
sql::Driver *driver;
try {
    driver = get_driver_instance();
} catch(exception &e) {
    cout << e.what() << endl;
}

cout << "aa" << endl;
return a.exec();

}

It build and compiles fine, however whenever it calls get_driver_instance(), it crashes and just give me XXX.exe has stopped working.

I'm using Qt Creator, windows Vista, my .pro file is as follow:

QT       += core
QT       += sql

QT       -= gui

TARGET = friendsDB

CONFIG   += console
CONFIG   -= app_bundle

LIBS += "C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\debug\mysqlcppconn.lib"
INCLUDEPATH += "C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include"

TEMPLATE = app


SOURCES += main.cpp

Any light shed would be greatly appreciated, thanks

From the documentation of MySQL Connector: "One problem that can occur is when the tools you use to build your application are not compatible with the tools used to build the binary versions of MySQL Connector/C++. Ideally you need to build your application with the same tools that were used to build the MySQL Connector/C++ binaries."

And to repeat the question of akira: Why don't you use the QMYSQL drivers?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM