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. Signals emitted from derived class trigger multiple slots
Forum Updated to NodeBB v4.3 + New Features

Signals emitted from derived class trigger multiple slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 1.7k 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.
  • P Offline
    P Offline
    PhTe
    wrote on last edited by PhTe
    #1

    Hi,
    i have a problem with some signals/slots.

    I have a base class which contains a signal:

    class ModalDialog : public QObject {
        Q_OBJECT
    
    ...
    
    signals:
        void dialogClosed(bool success);
    };
    

    and two derived classes:

    class WaitDeviceDialog : public ModalDialog {
        Q_OBJECT
    ...
        void close() {
            // Do some crazy stuff...
            emit dialogClosed();
        }
    };
    
    class ExportDialog : public ModalDialog {
        Q_OBJECT
    ...
        void close() {
            // Do some other stuff...
            emit dialogClosed();
        }
    };
    

    In my application i create instances of both derived classes and connect the signals:

    ...
    this->exportDlg = new ExportDialog();
    this->waitDlg = new WaitDeviceDialog();
    ...
    connect(this->exportDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onExportDialogClosed(bool)));
    connect(this->waitDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onWaitDialogClosed(bool)));
    ...
    

    My problem now is, that always both slots are executed regardless of which dialog the signal emitted.

    So if the ExportDialog was visible and closed it emitted the dialogClosed event and the corresponding onExportDialogClosed function is called. But also the onWaitDialogClosed function is called and i dont know why...

    Does somebody has an idea?

    Edit: It's Qt 5.4.1 on a Linux system.

    Taz742T jsulmJ 2 Replies Last reply
    0
    • P PhTe

      Hi,
      i have a problem with some signals/slots.

      I have a base class which contains a signal:

      class ModalDialog : public QObject {
          Q_OBJECT
      
      ...
      
      signals:
          void dialogClosed(bool success);
      };
      

      and two derived classes:

      class WaitDeviceDialog : public ModalDialog {
          Q_OBJECT
      ...
          void close() {
              // Do some crazy stuff...
              emit dialogClosed();
          }
      };
      
      class ExportDialog : public ModalDialog {
          Q_OBJECT
      ...
          void close() {
              // Do some other stuff...
              emit dialogClosed();
          }
      };
      

      In my application i create instances of both derived classes and connect the signals:

      ...
      this->exportDlg = new ExportDialog();
      this->waitDlg = new WaitDeviceDialog();
      ...
      connect(this->exportDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onExportDialogClosed(bool)));
      connect(this->waitDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onWaitDialogClosed(bool)));
      ...
      

      My problem now is, that always both slots are executed regardless of which dialog the signal emitted.

      So if the ExportDialog was visible and closed it emitted the dialogClosed event and the corresponding onExportDialogClosed function is called. But also the onWaitDialogClosed function is called and i dont know why...

      Does somebody has an idea?

      Edit: It's Qt 5.4.1 on a Linux system.

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by Taz742
      #2

      @PhTe
      You could write (show) a onExportDialogClosed and onWaitDialogClosed functions?

      Do what you want.

      1 Reply Last reply
      0
      • P PhTe

        Hi,
        i have a problem with some signals/slots.

        I have a base class which contains a signal:

        class ModalDialog : public QObject {
            Q_OBJECT
        
        ...
        
        signals:
            void dialogClosed(bool success);
        };
        

        and two derived classes:

        class WaitDeviceDialog : public ModalDialog {
            Q_OBJECT
        ...
            void close() {
                // Do some crazy stuff...
                emit dialogClosed();
            }
        };
        
        class ExportDialog : public ModalDialog {
            Q_OBJECT
        ...
            void close() {
                // Do some other stuff...
                emit dialogClosed();
            }
        };
        

        In my application i create instances of both derived classes and connect the signals:

        ...
        this->exportDlg = new ExportDialog();
        this->waitDlg = new WaitDeviceDialog();
        ...
        connect(this->exportDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onExportDialogClosed(bool)));
        connect(this->waitDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onWaitDialogClosed(bool)));
        ...
        

        My problem now is, that always both slots are executed regardless of which dialog the signal emitted.

        So if the ExportDialog was visible and closed it emitted the dialogClosed event and the corresponding onExportDialogClosed function is called. But also the onWaitDialogClosed function is called and i dont know why...

        Does somebody has an idea?

        Edit: It's Qt 5.4.1 on a Linux system.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @PhTe said in Signals emitted from derived class trigger multiple slots:

        emit dialogClosed();

        You do not pass true/false to the signal! Your signal has a bool parameter. It should actually not even compile.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Do you have any static/singleton stuff going on in the background?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            For some basic steps to debug this I would try:

            • comment one connect out. That way youcan actually see if you have the correct connect statement or if somewhere else in the code the problem is happening
            • change to the new QT5 Signal/Slot Syntax

            @jsulm that is one of the major reasons why I prefere the new over the old Syntax. This would indeed not compile with the new syntax but it should be valid in the old one, but should fail to execute the slot.


            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.

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

              For some basic steps to debug this I would try:

              • comment one connect out. That way youcan actually see if you have the correct connect statement or if somewhere else in the code the problem is happening
              • change to the new QT5 Signal/Slot Syntax

              @jsulm that is one of the major reasons why I prefere the new over the old Syntax. This would indeed not compile with the new syntax but it should be valid in the old one, but should fail to execute the slot.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @J.Hilk I don't mean the connect. This one should not compile if there is no such signal:

              emit dialogClosed();
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J.HilkJ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @J.Hilk I don't mean the connect. This one should not compile if there is no such signal:

                emit dialogClosed();
                
                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @jsulm oh, right. Might be a typo or the the signal is qactully defined with a default value:

                signals:
                    void dialogClosed(bool success=true);
                

                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.

                1 Reply Last reply
                0

                • Login

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