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. Getting strange debug output when calling QMetaObject::invokeMethod()
QtWS25 Last Chance

Getting strange debug output when calling QMetaObject::invokeMethod()

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdebugthreadinvokemethod
1 Posts 1 Posters 38 Views
  • 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.
  • S Offline
    S Offline
    Saviz
    wrote 20 days ago last edited by
    #1

    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 of DatabaseWorker to it. The DatabaseWorker handles all database interactions to improve performance and prevent the GUI thread from freezing during long operations. The Database is nothing more than a wrapper.

    To communicate with DatabaseWorker, I typically use QMetaObject::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 and DatabaseWorker 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() in DatabaseWorker, 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?

    1 Reply Last reply
    0

    1/1

    22 Apr 2025, 00:55

    • Login

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