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. QSqlTableModel - unable to find table
Forum Updated to NodeBB v4.3 + New Features

QSqlTableModel - unable to find table

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.1k Views 1 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.
  • MasterQM Offline
    MasterQM Offline
    MasterQ
    wrote on last edited by MasterQ
    #1

    Hi, once again.

    The main issue I am struggling with at the moment is that my QSqlTableModel gives an error while select(). It states "unable to find table Dokumente".

    But the table exists. See the following test:

    auto context = new DocumentsDbContext();
    
    qDebug() << "context->model()->select()" << context->model()->select();
    qDebug() << "context->model()->lastError()" << context->model()->lastError();
    qDebug();
    
    
    auto sql = "SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%';";
    auto query = new QSqlQuery(sql, context->database());
    qDebug() << "query->exec() #1" << query->exec();
    while(query->next()) {
         qDebug() << "query->record().value(\"name\")" << query->record().value("name").toString();
    }
    delete query;
    

    with following output:

    context->model()->select() false
    context->model()->lastError() QSqlError("", "Unable to find table Dokumente", "")
    
    context->database().isValid() true
    context->database().databaseName() "devel.db"
    context->database().connectionName() "documents"
    QFile::exists true
    context->database().driverName() "QSQLITE"
    query->exec() #1 true
    ...
    query->record().value("name") "Dokumente"
    ...
    

    What's going on here?

    DocumentsDbContext wrappes the QSqlDatabase and the QSqlTableModel.

    JonBJ 1 Reply Last reply
    0
    • MasterQM MasterQ

      Hi, once again.

      The main issue I am struggling with at the moment is that my QSqlTableModel gives an error while select(). It states "unable to find table Dokumente".

      But the table exists. See the following test:

      auto context = new DocumentsDbContext();
      
      qDebug() << "context->model()->select()" << context->model()->select();
      qDebug() << "context->model()->lastError()" << context->model()->lastError();
      qDebug();
      
      
      auto sql = "SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%';";
      auto query = new QSqlQuery(sql, context->database());
      qDebug() << "query->exec() #1" << query->exec();
      while(query->next()) {
           qDebug() << "query->record().value(\"name\")" << query->record().value("name").toString();
      }
      delete query;
      

      with following output:

      context->model()->select() false
      context->model()->lastError() QSqlError("", "Unable to find table Dokumente", "")
      
      context->database().isValid() true
      context->database().databaseName() "devel.db"
      context->database().connectionName() "documents"
      QFile::exists true
      context->database().driverName() "QSQLITE"
      query->exec() #1 true
      ...
      query->record().value("name") "Dokumente"
      ...
      

      What's going on here?

      DocumentsDbContext wrappes the QSqlDatabase and the QSqlTableModel.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @MasterQ
      It would be good to see the SQL statement reported as being executed for the context->model()->select() failure/Unable to find table Dokumente error?

      MasterQM 1 Reply Last reply
      0
      • JonBJ JonB

        @MasterQ
        It would be good to see the SQL statement reported as being executed for the context->model()->select() failure/Unable to find table Dokumente error?

        MasterQM Offline
        MasterQM Offline
        MasterQ
        wrote on last edited by
        #3

        @JonB

        qDebug() << "context->model()->SelectStatement()" << context->model()->SelectStatement();
        

        gives

        context->model()->SelectStatement() ""
        

        an empty string ??

        Christian EhrlicherC 1 Reply Last reply
        0
        • MasterQM MasterQ

          @JonB

          qDebug() << "context->model()->SelectStatement()" << context->model()->SelectStatement();
          

          gives

          context->model()->SelectStatement() ""
          

          an empty string ??

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please provide a minimal, compilable example and make sure the database is opened before a query is created.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          MasterQM 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            Please provide a minimal, compilable example and make sure the database is opened before a query is created.

            MasterQM Offline
            MasterQM Offline
            MasterQ
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            today I created a console testing application, copied all relevant stuff, and ...

            what do you think?

            Yes, it is working as intended, no issues, everything is fine. I then reimplemented all the testing code into my main project and ...

            what do you think?

            Yes, it is working also as intended, no issues, everything is fine.

            It is gone over night! There are no changes, except that I added some test methods.

            Yesterday I cleaned up the project and rebuilt it several times. No idea what happened.

            BTW; everything is fine is not really correct. I now get an error message at

             auto db = QSqlDatabase::addDatabase(m_driver, m_connectionname);
            
            qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter
            

            Also no changes in code from yesterday.

            But is has no real effect. The code is running without issues.

            Christian EhrlicherC 1 Reply Last reply
            0
            • MasterQM MasterQ

              @Christian-Ehrlicher

              today I created a console testing application, copied all relevant stuff, and ...

              what do you think?

              Yes, it is working as intended, no issues, everything is fine. I then reimplemented all the testing code into my main project and ...

              what do you think?

              Yes, it is working also as intended, no issues, everything is fine.

              It is gone over night! There are no changes, except that I added some test methods.

              Yesterday I cleaned up the project and rebuilt it several times. No idea what happened.

              BTW; everything is fine is not really correct. I now get an error message at

               auto db = QSqlDatabase::addDatabase(m_driver, m_connectionname);
              
              qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter
              

              Also no changes in code from yesterday.

              But is has no real effect. The code is running without issues.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @MasterQ said in QSqlTableModel - unable to find table:

              qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter

              Which exact Qt version do you use? Try to start it with QT_FATAL_WARNINGS to see where the message comes from.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              MasterQM 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @MasterQ said in QSqlTableModel - unable to find table:

                qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter

                Which exact Qt version do you use? Try to start it with QT_FATAL_WARNINGS to see where the message comes from.

                MasterQM Offline
                MasterQM Offline
                MasterQ
                wrote on last edited by
                #7

                @Christian-Ehrlicher

                I am using 6.6.1.

                setting environment variable QT_FATAL_WARNINGS=1 gives not much more information

                qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter
                Signal: SIGABRT (Aborted)
                
                

                The application stops at that point.

                With QT_FATAL_WARNINGS= 0, no difference to without QT_FATAL_WARNINGS. The app is running until the end without any additional output.

                Christian EhrlicherC 1 Reply Last reply
                0
                • MasterQM MasterQ

                  @Christian-Ehrlicher

                  I am using 6.6.1.

                  setting environment variable QT_FATAL_WARNINGS=1 gives not much more information

                  qt.core.qobject.connect: QObject::connect(QObject, Unknown): invalid nullptr parameter
                  Signal: SIGABRT (Aborted)
                  
                  

                  The application stops at that point.

                  With QT_FATAL_WARNINGS= 0, no difference to without QT_FATAL_WARNINGS. The app is running until the end without any additional output.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @MasterQ You should run it in a debugger to see where it asserts ...

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  MasterQM 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @MasterQ You should run it in a debugger to see where it asserts ...

                    MasterQM Offline
                    MasterQM Offline
                    MasterQ
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher said in QSqlTableModel - unable to find table:

                    @MasterQ You should run it in a debugger to see where it asserts ...

                    It is running in a debugger.

                    The current frames's file 'pthread_kill.c' is not found or its content differs from the compiled content. You may specify it manually.
                    

                    The editor is pointing to some assembler code.

                    I am using CLion.

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • MasterQM MasterQ

                      @Christian-Ehrlicher said in QSqlTableModel - unable to find table:

                      @MasterQ You should run it in a debugger to see where it asserts ...

                      It is running in a debugger.

                      The current frames's file 'pthread_kill.c' is not found or its content differs from the compiled content. You may specify it manually.
                      

                      The editor is pointing to some assembler code.

                      I am using CLion.

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Look at the backtrace... basic programming knowledge.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      2
                      • MasterQM Offline
                        MasterQM Offline
                        MasterQ
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher

                        you are right, that are basics. I just had it not on my focus. Please keep in mind that I am not a professional, just a hobbyist and a little bit out of shape about C++.

                        here is the backtrace:

                        __pthread_kill_implementation 0x00007ffff7099a1b
                        __pthread_kill_internal 0x00007ffff7099a1b
                        __GI___pthread_kill 0x00007ffff7099a1b
                        __GI_raise 0x00007ffff70428e6
                        __GI_abort 0x00007ffff70268b7
                        qAbort 0x00007ffff78b792c
                        qt_message_fatal<QString&> 0x00007ffff78edc05
                        qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *) 0x00007ffff78edc05
                        QMessageLogger::warning 0x00007ffff78b7f22
                        connectWarning 0x00007ffff78c17c5
                        QObjectPrivate::connectImpl 0x00007ffff79b015a
                        QObject::connectImpl 0x00007ffff79b0a2d
                        
                        QObject::connect<…> qobject.h:235
                        
                        QObject::connect<…> qobject.h:243
                        QtGlobalStatic::ApplicationHolder::pointer qapplicationstatic.h:53
                        QGlobalStatic::instance qglobalstatic.h:92
                        QGlobalStatic::operator() qglobalstatic.h:73
                        QSqlDatabasePrivate::driverDict 0x00007ffff7f85729
                        QSqlDatabasePrivate::init 0x00007ffff7f85729
                        QSqlDatabase::addDatabase 0x00007ffff7f85da2
                        libDatabase::DatabaseProvider::Database DatabaseProvider.cpp:41
                        Tests::databaseProvider Tests.cpp:39
                        main main.cpp:9
                        __libc_start_call_main 0x00007ffff7028150
                        __libc_start_main_impl 0x00007ffff7028209
                        _start 0x0000555555559d05
                        

                        I am far away from knowing Qt source code. I have started again with Qt/C++ after around 25 years of a break just three or four weeks ago.

                        The issue seems not to come from my code, but from somewhere deep in Qt itself.

                        for whom it may be of interest:
                        small test program on github reproducing the issue

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • MasterQM MasterQ

                          @Christian-Ehrlicher

                          you are right, that are basics. I just had it not on my focus. Please keep in mind that I am not a professional, just a hobbyist and a little bit out of shape about C++.

                          here is the backtrace:

                          __pthread_kill_implementation 0x00007ffff7099a1b
                          __pthread_kill_internal 0x00007ffff7099a1b
                          __GI___pthread_kill 0x00007ffff7099a1b
                          __GI_raise 0x00007ffff70428e6
                          __GI_abort 0x00007ffff70268b7
                          qAbort 0x00007ffff78b792c
                          qt_message_fatal<QString&> 0x00007ffff78edc05
                          qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *) 0x00007ffff78edc05
                          QMessageLogger::warning 0x00007ffff78b7f22
                          connectWarning 0x00007ffff78c17c5
                          QObjectPrivate::connectImpl 0x00007ffff79b015a
                          QObject::connectImpl 0x00007ffff79b0a2d
                          
                          QObject::connect<…> qobject.h:235
                          
                          QObject::connect<…> qobject.h:243
                          QtGlobalStatic::ApplicationHolder::pointer qapplicationstatic.h:53
                          QGlobalStatic::instance qglobalstatic.h:92
                          QGlobalStatic::operator() qglobalstatic.h:73
                          QSqlDatabasePrivate::driverDict 0x00007ffff7f85729
                          QSqlDatabasePrivate::init 0x00007ffff7f85729
                          QSqlDatabase::addDatabase 0x00007ffff7f85da2
                          libDatabase::DatabaseProvider::Database DatabaseProvider.cpp:41
                          Tests::databaseProvider Tests.cpp:39
                          main main.cpp:9
                          __libc_start_call_main 0x00007ffff7028150
                          __libc_start_main_impl 0x00007ffff7028209
                          _start 0x0000555555559d05
                          

                          I am far away from knowing Qt source code. I have started again with Qt/C++ after around 25 years of a break just three or four weeks ago.

                          The issue seems not to come from my code, but from somewhere deep in Qt itself.

                          for whom it may be of interest:
                          small test program on github reproducing the issue

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Thx for the backtrace. QSqlDatabasePrivate::driverDict() is gone in 6.7 but I would guess you did not instantiate a Q(Core)Application before use create a QSqlDatabase.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          1

                          • Login

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