QSqlTableModel - unable to find table
-
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.
-
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.
-
@MasterQ
It would be good to see the SQL statement reported as being executed for thecontext->model()->select()
failure/Unable to find table Dokumente
error? -
qDebug() << "context->model()->SelectStatement()" << context->model()->SelectStatement();
gives
context->model()->SelectStatement() ""
an empty string ??
Please provide a minimal, compilable example and make sure the database is opened before a query is created.
-
Please provide a minimal, compilable example and make sure the database is opened before a query is created.
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.
-
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.
@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.
-
@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.
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.
-
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.
@MasterQ You should run it in a debugger to see where it asserts ...
-
@MasterQ You should run it in a debugger to see where it asserts ...
@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-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.
Look at the backtrace... basic programming knowledge.
-
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 -
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 issueThx 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.