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. Update All Controls every 200ms
Forum Updated to NodeBB v4.3 + New Features

Update All Controls every 200ms

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 684 Views 2 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.
  • A Offline
    A Offline
    Armux
    wrote on last edited by
    #1

    Hey, guys :D

    I was trying to search/get some hints to solve my problem, but what i've found was hard to me since i'm really new with Qt.

    So, what's my problem?
    I have a main window with 5 checkboxes. The thing is: checkbox methods are called just if i change the state of the checkbox. But i don't want it. In every checkbox i have a check like:

    if (ui->checkBox->isChecked())
    {
       Do X;
    }
    
    else
    {
        Do Y;
    }
    

    So i want my program calling the methods for checkboxes every 200ms, even considering i didn't touched it.

    I've read something about connect and QTimer, but i'm still confused. :(

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Out of curiosity, why exactly do you want to check their state like that ?

      In any case, just connect your QTimer to a slot that implements that logic and you're pretty much done.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Armux
        wrote on last edited by
        #3

        Hi, SGaist :D

        I'm working with named pipes. The program in Qt is the server.

        if (ui->checkBox->isChecked())
        {
        ........ Make a call to write some infos in a named pipe;
        }

        else
        {
        ........ Make a call to write another infos in a named pipe;
        }

        In any case, just connect your QTimer to a slot that implements that logic and you're pretty much done.

        I was doing something like it inside MainWindow::MainWindow:

        QTimer *timer = new QTimer(this);
        connect(timer, &QTimer::timeout, this, QOverload<>::of(&MyConditionCheckerHere));
        timer->start(1000);

        But it's not working, i'm a little confused...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry, I failed to see the relation between a named pipe and the fact that you are polling these widgets.

          How did you determine that the slot is not called ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          1
          • SGaistS SGaist

            Sorry, I failed to see the relation between a named pipe and the fact that you are polling these widgets.

            How did you determine that the slot is not called ?

            A Offline
            A Offline
            Armux
            wrote on last edited by
            #5

            @SGaist said in Update All Controls every 200ms:

            Sorry, I failed to see the relation between a named pipe and the fact that you are polling these widgets.

            How did you determine that the slot is not called ?

            The thing i want is just make my program automatically check the state of the checkboxes EVERY 200ms. Just it. If checked, so write X to my pipe, if not checked, so write Y to my pipe.

            This is my problem, i don't know how to do it in a loop. :\

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You do not need a loop.

              QTimer is the right tool.

              What exactly is not working in your code ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              1
              • SGaistS SGaist

                You do not need a loop.

                QTimer is the right tool.

                What exactly is not working in your code ?

                A Offline
                A Offline
                Armux
                wrote on last edited by Armux
                #7

                @SGaist said in Update All Controls every 200ms:

                You do not need a loop.

                QTimer is the right tool.

                What exactly is not working in your code ?

                I created a new checkbox now called Updater. This is my method for Updater:

                void MainWindow::on_checkBox_2_stateChanged(int)
                {
                    QTimer *timer = new QTimer(this);
                    connect(ui->checkBox, SIGNAL(clicked()), this, SLOT(on_checkBox_stateChanged()));
                    timer->start(200);
                }
                

                My intention with the Updater checkbox is that it keeps calling MainWindow::on_checkBox_stateChanged(), because inside it i have the if conditions to write to my pipe with X or Y informations.

                The code from Updater isn't calling the another checkboxes methods.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Your timer is not connected to anything.
                  You create a new one every time that method is called.
                  You duplicate the connection every time that method is called.

                  Your logic is flawed.

                  As I suggested before, write one slot into which you do all your checkbox value stuff that you dump into your pipe.

                  Create only one timer, connect it to that slot and start it. That's all. If you want to toggle the timer from on to off based on one checkbox, then write a slot that you connect to the toggled signal of your checkbox and start/stop the timer based on the state of the checkbox.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Your timer is not connected to anything.
                    You create a new one every time that method is called.
                    You duplicate the connection every time that method is called.

                    Your logic is flawed.

                    As I suggested before, write one slot into which you do all your checkbox value stuff that you dump into your pipe.

                    Create only one timer, connect it to that slot and start it. That's all. If you want to toggle the timer from on to off based on one checkbox, then write a slot that you connect to the toggled signal of your checkbox and start/stop the timer based on the state of the checkbox.

                    A Offline
                    A Offline
                    Armux
                    wrote on last edited by
                    #9

                    @SGaist said in Update All Controls every 200ms:

                    Your timer is not connected to anything.
                    You create a new one every time that method is called.
                    You duplicate the connection every time that method is called.

                    Your logic is flawed.

                    As I suggested before, write one slot into which you do all your checkbox value stuff that you dump into your pipe.

                    Create only one timer, connect it to that slot and start it. That's all. If you want to toggle the timer from on to off based on one checkbox, then write a slot that you connect to the toggled signal of your checkbox and start/stop the timer based on the state of the checkbox.

                    Thanks for all your help, friend!! =D
                    I made it now with a tutorial about QTimer!

                    #Solved

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      You're welcome !

                      Out of curiosity, why do you need to send the checkbox status every 200ms ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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