Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMYSQL SIGSEGV
Forum Updated to NodeBB v4.3 + New Features

QMYSQL SIGSEGV

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 3 Posters 5.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #8

    What is that qrkcore library you are using ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    C 1 Reply Last reply
    0
    • SGaistS SGaist

      What is that qrkcore library you are using ?

      C Offline
      C Offline
      ckvsoft
      wrote on last edited by
      #9

      @SGaist
      This is a Part of my Application . Why?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #10

        Well... To know whether it's an external library you are using or something you are implementing.

        Do you have the same crash if you implement just a minimal application that connects to the database and does the queries ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ckvsoft
          wrote on last edited by
          #11

          @SGaist
          I will try this at weekend. Also i will test if MySQL and MariaDB has the same. The queries where made from the library. Thx for the time

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ckvsoft
            wrote on last edited by ckvsoft
            #12

            Hi
            I connect to a localhost mysql server and it seems to work. When i has running in the background some sql queries and i do at the same time from other window with the same connection any query it works.

            When i connect to a server via TCP it will crash.
            Edit: Its also with localhost, but the time is a bit longer ;(

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #13

              Can you trigger also that when using an application that's not using the QSql** classes ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ckvsoft
                wrote on last edited by
                #14

                I think i have found a solution ;-) Some Test will be good. I will enhance my tests.
                The Idea i found by reading http://doc.qt.io/qt-5/threads-modules.html

                Just my Application worked since 2015 with QSQLITE without troubles. But some users will also use MySQL.

                For the solution i have adapted a database manager for my requirement.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #15

                  So you're using multiple threads to write to your database ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  C 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    So you're using multiple threads to write to your database ?

                    C Offline
                    C Offline
                    ckvsoft
                    wrote on last edited by ckvsoft
                    #16

                    @SGaist
                    Yes. I Import JSON Files with an Import Walter Thread. Wenn a File is copied in a Directory it will Import and created new sql entries.
                    Nur Why SQlite has no Troubles?
                    I will also Move long Working Stuff to thread

                    Ob they GUI you also can do some queries by clicking Buttons

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      I'd say pure luck.

                      Are you creating one connection per thread like suggested in the documentation ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • C Offline
                        C Offline
                        ckvsoft
                        wrote on last edited by ckvsoft
                        #18

                        @SGaist
                        Yes. The DatabaseManager save the connections per thread into a

                        QHash<QThread*, QHash<QString, QSqlDatabase> > 
                        
                        

                        I have only one thread at a time wich write to the database. All others max. 4 to only select
                        Sorry for my "Austrian English" ;-)

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #19

                          Can you show how your are setting up the connections ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • C Offline
                            C Offline
                            ckvsoft
                            wrote on last edited by ckvsoft
                            #20

                            @SGaist

                            The first connection is in my first post
                            Than for every connection i call

                            QSqlDatabase dbc = DatabaseManager::database("CN");
                            QSqlQuery query(dbc)
                            .
                            .
                            

                            .

                            #include "databasemanager.h"
                            
                            #include <QSqlDatabase>
                            #include <QMutexLocker>
                            #include <QThread>
                            #include <QSqlError>
                            #include <QDebug>
                            
                            QMutex DatabaseManager::s_databaseMutex;
                            QHash<QThread*, QHash<QString, QSqlDatabase> > DatabaseManager::s_instances;
                            
                            QSqlDatabase DatabaseManager::database(const QString& connectionName)
                            {
                                QMutexLocker locker(&s_databaseMutex);
                                QThread *thread = QThread::currentThread();
                            
                                // if we have a connection for this thread, return it
                                QHash<QThread*, QHash<QString, QSqlDatabase> >::Iterator it_thread = s_instances.find(thread);
                                if (it_thread != s_instances.end()) {
                                    QHash<QString, QSqlDatabase>::iterator it_conn = it_thread.value().find(connectionName);
                                    if (it_conn != it_thread.value().end()) {
                                        QSqlDatabase connection = it_conn.value();
                            //            qDebug() << "Function Name: " << Q_FUNC_INFO << " found SQL connection instances Thread: " << thread->currentThreadId() << " Name: " << connectionName;
                                        if (connection.isValid())
                                            return it_conn.value();
                                    }
                                }
                            
                                // otherwise, create a new connection for this thread
                                QSqlDatabase connection = QSqlDatabase::cloneDatabase(
                                                              QSqlDatabase::database(connectionName),
                                                              QString("%1_%2").arg(connectionName).arg((int)thread));
                            
                                // open the database connection
                                // initialize the database connection
                                if (!connection.open()) {
                                    // Todo: Exeption Handling
                                    qCritical() << "Function Name: " << Q_FUNC_INFO << connection.lastError().text();
                                    return connection;
                                }
                            
                                qDebug() << "Function Name: " << Q_FUNC_INFO << " new SQL connection instances Thread: " << thread->currentThreadId() << " Name: " << connectionName;
                            
                                s_instances[thread][connectionName] = connection;
                                return connection;
                            }
                            
                            #ifndef DATABASEMANAGER_H
                            #define DATABASEMANAGER_H
                            
                            #include "qrkcore_global.h"
                            
                            #include <QMutex>
                            #include <QHash>
                            #include <QSqlDatabase>
                            
                            class QThread;
                            
                            class QRK_EXPORT DatabaseManager
                            {
                                public:
                                    static QSqlDatabase database(const QString& connectionName = QLatin1String(QSqlDatabase::defaultConnection));
                                private:
                                    static QMutex s_databaseMutex;
                                    static QHash<QThread*, QHash<QString, QSqlDatabase>> s_instances;
                            
                            };
                            
                            #endif // DATABASEMANAGER_H
                            

                            I found the code and adapted it for my requirement.

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              ckvsoft
                              wrote on last edited by
                              #21

                              So. I made some tests with create more than 1000 receipts and do concurrent imports with 10000 Products and do some select. I seems it works now without any troubles localhost and IP also over slow connection over the internet.

                              i think it fix my problem.
                              lg chris

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved