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. How to quit an eventLoop connect to a signal containing arguments?
Forum Updated to NodeBB v4.3 + New Features

How to quit an eventLoop connect to a signal containing arguments?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 659 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.
  • Y Offline
    Y Offline
    Ylvy
    wrote on last edited by
    #1

    I'm getting this error in the evenLoop.quit() line:

    E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"

    QEventLoop eventLoop;
    
    connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text)
    {
            qDebug() << text;
            eventLoop.quit();
    });
    
    eventLoop.exec();
    

    What the proper way to quit the loop in this case?

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • Y Ylvy

      I'm getting this error in the evenLoop.quit() line:

      E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"

      QEventLoop eventLoop;
      
      connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text)
      {
              qDebug() << text;
              eventLoop.quit();
      });
      
      eventLoop.exec();
      

      What the proper way to quit the loop in this case?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #4

      @Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:

      eventLoop.quit();

      I can't test, but don't you mean this->quit() or just quit() since &eventLoop is the this for the slot lambda?

      If not that, does it make any difference here if you use [&] instead of [=]?

      Christian EhrlicherC Y 2 Replies Last reply
      0
      • Y Ylvy

        I'm getting this error in the evenLoop.quit() line:

        E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"

        QEventLoop eventLoop;
        
        connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text)
        {
                qDebug() << text;
                eventLoop.quit();
        });
        
        eventLoop.exec();
        

        What the proper way to quit the loop in this case?

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

        Apart from the fact that I don't see a need for a local eventloop - how is you signalCancel defined?

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

        Y 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Apart from the fact that I don't see a need for a local eventloop - how is you signalCancel defined?

          Y Offline
          Y Offline
          Ylvy
          wrote on last edited by Ylvy
          #3

          @Christian-Ehrlicher
          The event loop is to wait the click in one of the MsgBox buttons.

          QT_BEGIN_NAMESPACE
          namespace Ui { class MsgBox; };
          QT_END_NAMESPACE
          
          class MsgBox : public QWidget
          {
              Q_OBJECT
          public:
              Ui::MsgBox* m_ui;
              MsgBox(QWidget* parent)
              void cancel();
          signals:
              void signalCancel(QString text);
          };
          
          MsgBox::MsgBox(QWidget* parent) : QWidget(parent)
              , m_ui(new Ui::MsgBox())
          {
          	m_ui->setupUi(this);
          	connect(m_ui->cancel, &QPushButton::clicked, this, &MsgBox::cancel);
          }
          
          void MsgBox::cancel()
          {
          	emit signalCancel("test 123");
          }
          Christian EhrlicherC 1 Reply Last reply
          0
          • Y Ylvy

            I'm getting this error in the evenLoop.quit() line:

            E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"

            QEventLoop eventLoop;
            
            connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text)
            {
                    qDebug() << text;
                    eventLoop.quit();
            });
            
            eventLoop.exec();
            

            What the proper way to quit the loop in this case?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #4

            @Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:

            eventLoop.quit();

            I can't test, but don't you mean this->quit() or just quit() since &eventLoop is the this for the slot lambda?

            If not that, does it make any difference here if you use [&] instead of [=]?

            Christian EhrlicherC Y 2 Replies Last reply
            0
            • JonBJ JonB

              @Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:

              eventLoop.quit();

              I can't test, but don't you mean this->quit() or just quit() since &eventLoop is the this for the slot lambda?

              If not that, does it make any difference here if you use [&] instead of [=]?

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

              @JonB said in How to quit an eventLoop connect to a signal containing arguments?:

              If not that, does it make any difference here if you use [&] instead of [=]?

              You're correct - QEventLoop is an QObject and therefore can't be copied.

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

              1 Reply Last reply
              1
              • JonBJ JonB

                @Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:

                eventLoop.quit();

                I can't test, but don't you mean this->quit() or just quit() since &eventLoop is the this for the slot lambda?

                If not that, does it make any difference here if you use [&] instead of [=]?

                Y Offline
                Y Offline
                Ylvy
                wrote on last edited by
                #6

                @JonB with [&] it work correctly, thank you all!

                1 Reply Last reply
                0
                • Y Ylvy has marked this topic as solved on
                • Y Ylvy

                  @Christian-Ehrlicher
                  The event loop is to wait the click in one of the MsgBox buttons.

                  QT_BEGIN_NAMESPACE
                  namespace Ui { class MsgBox; };
                  QT_END_NAMESPACE
                  
                  class MsgBox : public QWidget
                  {
                      Q_OBJECT
                  public:
                      Ui::MsgBox* m_ui;
                      MsgBox(QWidget* parent)
                      void cancel();
                  signals:
                      void signalCancel(QString text);
                  };
                  
                  MsgBox::MsgBox(QWidget* parent) : QWidget(parent)
                      , m_ui(new Ui::MsgBox())
                  {
                  	m_ui->setupUi(this);
                  	connect(m_ui->cancel, &QPushButton::clicked, this, &MsgBox::cancel);
                  }
                  
                  void MsgBox::cancel()
                  {
                  	emit signalCancel("test 123");
                  }
                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:

                  m_ui

                  this is leaking.

                  Still don't understand why you are blocking the execution with a local eventloop.

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

                  Y 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:

                    m_ui

                    this is leaking.

                    Still don't understand why you are blocking the execution with a local eventloop.

                    Y Offline
                    Y Offline
                    Ylvy
                    wrote on last edited by
                    #8

                    @Christian-Ehrlicher what is leaking? the ui i destructed in the class destructor?

                    Still don't understand why you are blocking the execution with a local eventloop.

                    The execution is blocked until one of the buttons of the class is clicked, how else i would block it until the click?

                    JonBJ 1 Reply Last reply
                    0
                    • Y Ylvy

                      @Christian-Ehrlicher what is leaking? the ui i destructed in the class destructor?

                      Still don't understand why you are blocking the execution with a local eventloop.

                      The execution is blocked until one of the buttons of the class is clicked, how else i would block it until the click?

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #9

                      @Ylvy
                      It is not clear why you want to block till a button is clicked from a QWidget.

                      In any case is QDialog and exec(), a modal dialog, not what you want here?

                      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