Results 1 to 2 of 2

Thread: Crash while connecting to MySQL

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Crash while connecting to MySQL

    I have a thread that opens a MySQL connection, executes a SELECT query, then closes the connection. Sometimes it crashes with a segmentation fault while trying to establish the connection. This is the backtrace I get:

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1246762096 (LWP 5786)]
    0xb51e232e in my_stat () from /usr/lib/libmysqlclient_r.so.15
    (gdb) bt
    #0 0xb51e232e in my_stat () from /usr/lib/libmysqlclient_r.so.15
    #1 0xb51dad95 in escape_quotes_for_mysql () from /usr/lib/libmysqlclient_r.so.15
    #2 0xb51db675 in get_charsets_dir () from /usr/lib/libmysqlclient_r.so.15
    #3 0xb51db7a9 in get_charset_by_csname () from /usr/lib/libmysqlclient_r.so.15
    #4 0xb51f80e9 in mysql_set_character_set () from /usr/lib/libmysqlclient_r.so.15
    #5 0xb6e96652 in QMYSQLDriver::open (this=0x81308c0, db=@0x80e6638, user=@0x80e663c, password=@0x80e6640, host=@0x80e6644, port=3306, connOpts=@0x80e6650)
    at ../../../sql/drivers/mysql/qsql_mysql.cpp:1091
    #6 0xb7ebb28e in QSqlDatabase::open (this=0xb5afe2d0) at kernel/qsqldatabase.cpp:792
    #7 0x0806278f in DbThread::run (this=0x80e0480) at dbthread.cpp:61
    #8 0xb72b0c09 in QThreadPrivate::start (arg=0x80e0480) at thread/qthread_unix.cpp:146
    #9 0xb724e112 in start_thread () from /lib/libpthread.so.0
    #10 0xb70c32ee in clone () from /lib/libc.so.6
    My code is like this:

    Qt Code:
    1. void DbThread::run()
    2. {
    3. QString connectionName = "DbThread-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz");
    4.  
    5. {
    6. // Connect to the database server
    7. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", connectionName);
    8. db.setHostName(m_host);
    9. db.setPort(m_port);
    10. db.setDatabaseName(m_database);
    11. db.setUserName(m_userName);
    12. db.setPassword(m_password);
    13. bool ok = db.open();
    14. if(!ok) {
    15. emit error(QString(tr("Error connecting to the database:\n\n%1")).arg(db.lastError().text()));
    16. return;
    17. }
    18.  
    19. QSqlQuery query(db);
    20. query.exec("SELECT ...");
    21. if(query.next()) {
    22. ...
    23. emit resultsOfMyQuery(...);
    24. }
    25. db.close();
    26. }
    27.  
    28. QSqlDatabase::removeDatabase(connectionName);
    29. }
    To copy to clipboard, switch view to plain text mode 

    It seems to be due to the MySQL client library but I wanted to ask here before going to the MySQL forums. Anyone had this problem and was able to solve it?

    I'm using Qt 4.2.2 under openSUSE 10.2, although I also compiled it under Windows for other clients and it worked perfectly there.
    Last edited by jacek; 9th January 2007 at 12:52. Reason: changed [code] to [quote]

Similar Threads

  1. Connection to MySQL - windows
    By Peter34 in forum Qt Programming
    Replies: 18
    Last Post: 30th October 2006, 18:54
  2. Qt 4.1.4 & Mysql 5 on Linux x64
    By bothapn in forum Installation and Deployment
    Replies: 7
    Last Post: 4th August 2006, 13:23
  3. connecting to MySQL through it's API
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 20
    Last Post: 30th May 2006, 23:22
  4. Error connecting to MySQL
    By probine in forum Qt Programming
    Replies: 20
    Last Post: 23rd February 2006, 23:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.