I’m using Qt 5.0.0 on Windows 7 ×64 (personal compile – MinGW x64). I added MySQL support in configuration and also MySQL is installed on system. MySQL libraries, headers and are visible in application.
Program crashes on opening database. I open database like this:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName("My DB name");
db.setUserName("root");
db.setPassword("My password");
db.setHostName("localhost");
db.setPort(3306);
try{
db.open(); // <=== Crashes without throwing an exception
}
catch(std::exception e)
{
std::cout << e.what() << std::endl;
}
Notes:
qDebug() << QSqlDatabase::drivers();
prints
("QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QSQLITE")
Problem signature generated by operating system looks like this:
Problem Event Name: APPCRASH
Application Name: CMS.exe
Application Version: 0.0.0.0
Application Timestamp: 51010cdd
Fault Module Name: Qt5Sql.dll
Fault Module Version: 5.0.0.0
Fault Module Timestamp: 50f6b734
Exception Code: c0000005
Exception Offset: 00000000000df950
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033
Additional Information 1: db69
Additional Information 2: db697f824a06df6631cf05ed1f197e16
Additional Information 3: 1d76
Additional Information 4: 1d7605bf295c1c2cfcbfc6bfcec7c569
I generate .a file using gendef and dlltool this way:
gendef libmysql.dll
dlltool --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a
Qt is configured with -qt-sql-mysql
rather than -plugin-sql-mysql
. ( What is difference? )
Since your program is crashing without catching the exception (and I note that you've written as a catch-all) I would tend to assume the crash is happening BEFORE the try block.
Try wrapping the declaration of 'db' and the setting of it's properties in a try-catch (even if only temporarily).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With