Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52438

Qt::UniqueConnection not working with lambda slots

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.9.0 Alpha
    • 5.3.2
    • Documentation
    • None
    • Windows 7

    Description

      Consider the following code:

      mainwindow.h
      public slots:
         void testSlotA();
      signals:
          void testSignal(int x);
      private:
          int m_x = 0;
      
      {code=title=mainwindow.cpp}

      void MainWindow::testSlotA()
      {
      m_x++;
      qDebug() << "?? PING" << m_x;
      connect(this, &MainWindow::testSignal, this, [=](int x)

      { qDebug() << "!! PONG" << x; }

      , Qt::UniqueConnection);

      emit testSignal(m_x);
      }

      
      

      Now if I call testSlotA 3 times it produces the following output:

      ?? PING 1
      !! PONG 1
      ?? PING 2
      !! PONG 2
      !! PONG 2
      ?? PING 3
      !! PONG 3
      !! PONG 3
      !! PONG 3
      

      This is wrong, using Qt::UniqueConnection the output should be:

      ?? PING 1
      !! PONG 1
      ?? PING 2
      !! PONG 2
      ?? PING 3
      !! PONG 3
      

      Attachments

        For Gerrit Dashboard: QTBUG-52438
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            rig_work R G
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes