Getting strange debug output when calling QMetaObject::invokeMethod()
-
I have a GUI thread running in QML, which contains an instance of my
Database
class. Inside this class, I create a dedicated worker thread and move an instance ofDatabaseWorker
to it. TheDatabaseWorker
handles all database interactions to improve performance and prevent the GUI thread from freezing during long operations. TheDatabase
is nothing more than a wrapper.To communicate with
DatabaseWorker
, I typically useQMetaObject::invokeMethod()
from the Database class and listen to signals coming back. Here is a sample:void Database::findPatient(const int patientID) { QMetaObject::invokeMethod( m_DatabaseWorker, &DatabaseWorker::findPatient, Qt::QueuedConnection, patientID ); } // A signal will be emitted by the method, which I will connect and listen to...
Both instances of the method in
Database
andDatabaseWorker
have the same signature and only one variation exists.This setup has been working well overall. However, I’m currently encountering a strange issue. I have a method called
createPatient()
inDatabaseWorker
, which internally calls an overloaded version. I use this approach because I plan to add another variant later that performs the same operation without using a transaction.Here are the signatures:
// A wrapper that calls into `DatabaseWorker::createPatient()`. void Database::createPatient(bool useTransaction, const QString &firstName, const QString &lastName, int birthYear, const QString &phoneNumber, const QString &email, const QString &gender, const QString &maritalStatus); // This method will do some extra work depending on if 'useTransaction' is set. void DatabaseWorker::createPatient(bool useTransaction, const QString &firstName, const QString &lastName, int birthYear, const QString &phoneNumber, const QString &email, const QString &gender, const QString &maritalStatus); // The actual logic of creating a new patient. void DatabaseWorker::createPatient(const QString &firstName, const QString &lastName, int birthYear, const QString &phoneNumber, const QString &email, const QString &gender, const QString &maritalStatus);
Due to the overload signatures,
QMetaObject::invokeMethod()
requires me to do something like this:void Database::createPatient(bool useTransaction, const QString &firstName, const QString &lastName, int birthYear, const QString &phoneNumber, const QString &email, const QString &gender, const QString &maritalStatus) { QMetaObject::invokeMethod( m_DatabaseWorker, QOverload< bool, const QString&, const QString&, int, const QString&, const QString&, const QString&, const QString& >::of(&DatabaseWorker::createPatient), Qt::QueuedConnection, useTransaction, firstName, lastName, birthYear, phoneNumber, email, gender, maritalStatus ); }
The odd part is that even though the functionality works correctly and the patient record is created successfully, some unexpected and unreadable lines are printed to the output. These lines appear even though I have no
qDebug()
or other logging statements in the code at that point.unknown (Line: 0) >> 0x1dfc9593390 unknown (Line: 0) >> 3758096383
I'm not sure why these messages are being printed or what is causing them. What could be the reason for this behavior, and how can I resolve it?