Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application crashes when opening a MySQL database

Tags:

mysql

qt

qt5

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? )

like image 889
sorush-r Avatar asked Nov 12 '22 12:11

sorush-r


1 Answers

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).

like image 107
Christopher J Smith Avatar answered Nov 15 '22 07:11

Christopher J Smith