Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Slot Mechanism

Slot Mechanism

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 2 Posters 789 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.
  • E Offline
    E Offline
    ELIF
    wrote on last edited by
    #1

    I have an slot mechanism.If I continuously click pushButtonx I get the (different) values on pushButtony .What I want to do is click the button once and get different values continuously.How to do this? Thanks in advance.

            connect(pushButtonx, &QPushButton::pressed, this,[=]() {
                QString textmessage = QString::number(ethernetThread->counter);
                pushButtony->setText(textmessage);
            });
    
    J.HilkJ 1 Reply Last reply
    0
    • E ELIF

      I have an slot mechanism.If I continuously click pushButtonx I get the (different) values on pushButtony .What I want to do is click the button once and get different values continuously.How to do this? Thanks in advance.

              connect(pushButtonx, &QPushButton::pressed, this,[=]() {
                  QString textmessage = QString::number(ethernetThread->counter);
                  pushButtony->setText(textmessage);
              });
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @ELIF said in Slot Mechanism:

      What I want to do is click the button once and get different values continuously

      by starting a QTimer on your button push and connecting to the timeout signal
      https://doc.qt.io/qt-5/qtimer.html


      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
      1
      • E Offline
        E Offline
        ELIF
        wrote on last edited by
        #3

        But this
        connect(pushButtonx, &QPushButton::pressed, this,= {
        QString textmessage = QString::number(ethernetThread->counter);
        pushButtony->setText(textmessage);
        });
        construction does not have signal name or a slot name.I have not a timeout() signal or update() slot.

        // QTimer *timer1 = new QTimer(this);
        // connect(timer1, SIGNAL(timeout()), this, SLOT(update()));
        // timer1->start(1000);

        J.HilkJ 1 Reply Last reply
        0
        • E ELIF

          But this
          connect(pushButtonx, &QPushButton::pressed, this,= {
          QString textmessage = QString::number(ethernetThread->counter);
          pushButtony->setText(textmessage);
          });
          construction does not have signal name or a slot name.I have not a timeout() signal or update() slot.

          // QTimer *timer1 = new QTimer(this);
          // connect(timer1, SIGNAL(timeout()), this, SLOT(update()));
          // timer1->start(1000);

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

          @ELIF so you like lambdas, so I but a lambda in your lambda.

          connect(pushButtonx, &QPushButton::pressed, this,[=]()->void {
                QTimer *neverEndingUpdateTimer(new QTimer());
                connect(neverEndingUpdateTimer, QTimer::timeout, this, [=]()->void{
                          QString textmessage = QString::number(ethernetThread->counter);
                          pushButtony->setText(textmessage);
                });
                neverEndingUpdateTimer->start(20);
          });
          

          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
          1
          • E Offline
            E Offline
            ELIF
            wrote on last edited by
            #5

            Thank you very much I appreciate it :)

                QTimer *neverEndingUpdateTimer(new QTimer());
                connect(pushButtonx, &QPushButton::pressed, this,[=]()->void {
            
                      connect(neverEndingUpdateTimer, &QTimer::timeout , this, [=]()->void{
                      QString textmessage = QString::number(ethernetThread->counter);
                      pushButtony->setText(textmessage);
                      }
                      );
                      neverEndingUpdateTimer->start(20);
                });
            

            I write &QTimer::timeout instead of QTimer::timeout ,then it works.

            J.HilkJ 1 Reply Last reply
            1
            • E ELIF

              Thank you very much I appreciate it :)

                  QTimer *neverEndingUpdateTimer(new QTimer());
                  connect(pushButtonx, &QPushButton::pressed, this,[=]()->void {
              
                        connect(neverEndingUpdateTimer, &QTimer::timeout , this, [=]()->void{
                        QString textmessage = QString::number(ethernetThread->counter);
                        pushButtony->setText(textmessage);
                        }
                        );
                        neverEndingUpdateTimer->start(20);
                  });
              

              I write &QTimer::timeout instead of QTimer::timeout ,then it works.

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

              @ELIF Typo an my part, but nice spotting :D

              this may in general work, but its just a proof of concept, the QTimer isntance is leaked, there's no way to stop the timer once its running and you will get multiple timer running, wenn you click multiple times on the button

              and, the naming of this: ethernetThread->counter lets me think you're accessing variables across threads without safeguards


              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
              1
              • E Offline
                E Offline
                ELIF
                wrote on last edited by ELIF
                #7

                @J-Hilk said in Slot Mechanism:

                this may in general work, but its just a proof of concept, the QTimer isntance is leaked, there's no way to stop the timer once its running and you will get multiple timer running, wenn you click multiple times on the button
                and, the naming of this: ethernetThread->counter lets me think you're accessing variables across threads without safeguards

                Actually I get data's from ethernet with using zmq. The naming of ethernetThread->counter is : ethernetThread is a EthernetThread class object, counter is a member of this class.I have server code and client code EthernetThread class is the client code.Purpose of this study is design a radar screen with QT .

                Hopefully I will achieve it.Thank you :)

                1 Reply Last reply
                1

                • Login

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