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. QObject::connect behaves different when using SLOTS() and SIGNALS() makro
Forum Updated to NodeBB v4.3 + New Features

QObject::connect behaves different when using SLOTS() and SIGNALS() makro

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 300 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.
  • M Offline
    M Offline
    MaximilianM
    wrote on last edited by
    #1

    Hi all,

    i have a problem updgrading an application from Qt 6.2 to 6.7 (I also tried 6.5 there is the same error).

    There is some weird code which creates a trigger on the stack and when the function closes it should emmit the trigger Signal when the function is done (Because of multiple return statements). Can someone tell me why it does not work anymore?

    Does not work in 6.5 or 6.7 (Original from 6.2):

    QAction close_notification_action("close_notification_action");
    QObject::connect(&close_notification_action, &QAction::destroyed, &close_notification_action, &QAction::trigger, Qt::DirectConnection);
    

    The Problem is independent of Qt::DirectConnection or AutoConnection or anything like that.

    Exits with QtPrivate::assertObjectType<QAction> :

            Q_ASSERT_X(cast(o), Obj::staticMetaObject.className(),
                       "Called object is not of the correct type (class destructor may have already run)");
    

    Works:

      QAction close_notification_action("close_notification_action");
      QObject::connect(&close_notification_action, SIGNAL(destroyed()), &close_notification_action, SLOT(trigger()));
    

    Somehow the destroyed Signal seems to be emmited at different moments?

    Thanks for you help!

    Christian EhrlicherC J.HilkJ 2 Replies Last reply
    0
    • M MaximilianM

      Hi all,

      i have a problem updgrading an application from Qt 6.2 to 6.7 (I also tried 6.5 there is the same error).

      There is some weird code which creates a trigger on the stack and when the function closes it should emmit the trigger Signal when the function is done (Because of multiple return statements). Can someone tell me why it does not work anymore?

      Does not work in 6.5 or 6.7 (Original from 6.2):

      QAction close_notification_action("close_notification_action");
      QObject::connect(&close_notification_action, &QAction::destroyed, &close_notification_action, &QAction::trigger, Qt::DirectConnection);
      

      The Problem is independent of Qt::DirectConnection or AutoConnection or anything like that.

      Exits with QtPrivate::assertObjectType<QAction> :

              Q_ASSERT_X(cast(o), Obj::staticMetaObject.className(),
                         "Called object is not of the correct type (class destructor may have already run)");
      

      Works:

        QAction close_notification_action("close_notification_action");
        QObject::connect(&close_notification_action, SIGNAL(destroyed()), &close_notification_action, SLOT(trigger()));
      

      Somehow the destroyed Signal seems to be emmited at different moments?

      Thanks for you help!

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

      The behavior is different in the time when the signal / slot connection is deleted. With pmf style it is done later (during QObject dtor) and therfore the assert.
      Your connect does not do anything with the string based one and would likely crash when the assert would not be there.

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

      M 1 Reply Last reply
      2
      • M MaximilianM

        Hi all,

        i have a problem updgrading an application from Qt 6.2 to 6.7 (I also tried 6.5 there is the same error).

        There is some weird code which creates a trigger on the stack and when the function closes it should emmit the trigger Signal when the function is done (Because of multiple return statements). Can someone tell me why it does not work anymore?

        Does not work in 6.5 or 6.7 (Original from 6.2):

        QAction close_notification_action("close_notification_action");
        QObject::connect(&close_notification_action, &QAction::destroyed, &close_notification_action, &QAction::trigger, Qt::DirectConnection);
        

        The Problem is independent of Qt::DirectConnection or AutoConnection or anything like that.

        Exits with QtPrivate::assertObjectType<QAction> :

                Q_ASSERT_X(cast(o), Obj::staticMetaObject.className(),
                           "Called object is not of the correct type (class destructor may have already run)");
        

        Works:

          QAction close_notification_action("close_notification_action");
          QObject::connect(&close_notification_action, SIGNAL(destroyed()), &close_notification_action, SLOT(trigger()));
        

        Somehow the destroyed Signal seems to be emmited at different moments?

        Thanks for you help!

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @MaximilianM seems more like a fix than a regression in my opinion.

        Doesn't make much sense that you would trigger a slot on an object that signalled the world that it was destroyed. Especially if the "Slot" just emits an other signal.

        Have you tried connecting directly to the slot that QAction::triggered is connect to?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        M 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @MaximilianM seems more like a fix than a regression in my opinion.

          Doesn't make much sense that you would trigger a slot on an object that signalled the world that it was destroyed. Especially if the "Slot" just emits an other signal.

          Have you tried connecting directly to the slot that QAction::triggered is connect to?

          M Offline
          M Offline
          MaximilianM
          wrote on last edited by
          #4

          @J-Hilk Your absolutly right that there are cleaner ways of programming this. This is somewhat older code and i dont want to touch it to much. But i definetly will think about changing it. Thanks for your opinion!

          1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            The behavior is different in the time when the signal / slot connection is deleted. With pmf style it is done later (during QObject dtor) and therfore the assert.
            Your connect does not do anything with the string based one and would likely crash when the assert would not be there.

            M Offline
            M Offline
            MaximilianM
            wrote on last edited by
            #5

            @Christian-Ehrlicher So i checked that and it seems you are right. That the string based emit does nothing. That explains a lot. Thanks for you help!

            1 Reply Last reply
            1
            • M MaximilianM has marked this topic as solved on

            • Login

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