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 every time check variable value?

How to every time check variable value?

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

    Hello Everyone,

    How i can check every time a value of variable so that if it crosses a threshold Qcheckbox should be checked.
    For example
    IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
    Thanks in advance.

    K 1 Reply Last reply
    0
    • R rockon209

      Hello Everyone,

      How i can check every time a value of variable so that if it crosses a threshold Qcheckbox should be checked.
      For example
      IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
      Thanks in advance.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @rockon209

      Without a couple of more details there is little to answer besides the obvious (some if statements and an update shall do).

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rockon209
        wrote on last edited by rockon209
        #3

        @koahnig

        For example
        IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
        I know if statement should be used but how I know or check that the variable value is changed?

        J.HilkJ jsulmJ K 3 Replies Last reply
        0
        • R rockon209

          @koahnig

          For example
          IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
          I know if statement should be used but how I know or check that the variable value is changed?

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

          @rockon209 That is still a super generic question.

          QCheckBox *cBox = new QCheckBox();
          cBox->show();
          
          for(int i =0 i < 100000; i++) {
               if(i == 100){
                    cBox->setChecked(true);
                    break;
               }
          }
          

          thats the most generic answer I could think of!?

          Edit:
          Rereading your 2nd post I think you may want something along this?
          A QSpinBox that when a certain value is reached a checkbox ist checked?

          //Constructor
          connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(checkValue(int));
          
          //Check function
          void checkValue(int value){
              if( value == 100)
                 ui->checkBox->setChecked(true);
              else 
                ui->checkBox->setChecked(false);
          }
          

          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
          4
          • R rockon209

            @koahnig

            For example
            IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
            I know if statement should be used but how I know or check that the variable value is changed?

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

            @rockon209 Do you want to know whether the variable was changed or do you want to know whether that variable reached a threshold? It is not really clear from your description. And: do you want to check that variable once in the function or in a loop?

            1 Reply Last reply
            1
            • R Offline
              R Offline
              rockon209
              wrote on last edited by rockon209
              #6

              @jsulm
              I want to check if the variable is changed or not. But the varaible will be updated somewhere else not in the function
              Letme explain in detail
              if in an application there is a start button. I pressed the start button and some tasks are going on. When these tasks are going on, with a temperature sensor which am using i got a signal and this signal means that i want to stop the application how can i instruct the application to stop? the temp sensor is connected to PC via USB and I can communicate with the sensor

              jsulmJ 1 Reply Last reply
              0
              • R rockon209

                @jsulm
                I want to check if the variable is changed or not. But the varaible will be updated somewhere else not in the function
                Letme explain in detail
                if in an application there is a start button. I pressed the start button and some tasks are going on. When these tasks are going on, with a temperature sensor which am using i got a signal and this signal means that i want to stop the application how can i instruct the application to stop? the temp sensor is connected to PC via USB and I can communicate with the sensor

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

                @rockon209 I still don't understand the problem. To stop call http://doc.qt.io/qt-5/qcoreapplication.html#quit...

                1 Reply Last reply
                0
                • R rockon209

                  @koahnig

                  For example
                  IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
                  I know if statement should be used but how I know or check that the variable value is changed?

                  K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  @rockon209 said in How to every time check variable value?:

                  @koahnig

                  For example
                  IF a function is running and I want to start check the variable value which is not in that function and if that variable value reaches a certain threshold Qcheckbox should be checked.
                  I know if statement should be used but how I know or check that the variable value is changed?

                  But there is exactly the point. One can suggest many different things which are not going to suitable to what you are actually looking for.

                  Some suggestions are when you are having changed something in another QObject derived class (@J-Hilk). That might be already sufficient. When you have something completely different other means are required. For instance you may required a QTimer which triggers to check your values on a regular basis.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rockon209
                    wrote on last edited by
                    #9

                    @koahnig

                    Yes I know that with Qtimer i can check the value on regular basis. But is there any other way intead of Qtimer because I have used lot of Qtimers in my Application.

                    jsulmJ 1 Reply Last reply
                    0
                    • R rockon209

                      @koahnig

                      Yes I know that with Qtimer i can check the value on regular basis. But is there any other way intead of Qtimer because I have used lot of Qtimers in my Application.

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

                      @rockon209 Can't you just emit a signal each time this variable is changed? Then everyone interested to this variable can connect to this signal and do what ever needs to be done. This way there is no need to check actively at all...

                      1 Reply Last reply
                      1
                      • R Offline
                        R Offline
                        rockon209
                        wrote on last edited by rockon209
                        #11

                        @J-Hilk @koahnig @jsulm
                        I will explain again
                        I pressed the start button, and I start recording some values from other sensors. And suddenly the temp value is 100 degree so therefore I want to stop the application. So when I am recording the values from other sensor I should everytime keep an eye on the temp to check the value. How can i do it. One way i know is use Qtimmer and every one seconnd check the value of the Temp sensor. Is there any other way instead of this?

                        jsulmJ 2 Replies Last reply
                        0
                        • R rockon209

                          @J-Hilk @koahnig @jsulm
                          I will explain again
                          I pressed the start button, and I start recording some values from other sensors. And suddenly the temp value is 100 degree so therefore I want to stop the application. So when I am recording the values from other sensor I should everytime keep an eye on the temp to check the value. How can i do it. One way i know is use Qtimmer and every one seconnd check the value of the Temp sensor. Is there any other way instead of this?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12
                          This post is deleted!
                          1 Reply Last reply
                          1
                          • R rockon209

                            @J-Hilk @koahnig @jsulm
                            I will explain again
                            I pressed the start button, and I start recording some values from other sensors. And suddenly the temp value is 100 degree so therefore I want to stop the application. So when I am recording the values from other sensor I should everytime keep an eye on the temp to check the value. How can i do it. One way i know is use Qtimmer and every one seconnd check the value of the Temp sensor. Is there any other way instead of this?

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

                            @rockon209 If you don't get the temperature already on a regular basis then you need to check it periodically using a QTimer. Alternative would be to have a thread where you read the temperature sleep for some time and read again in a loop. But using a QTimer is way easier!

                            1 Reply Last reply
                            2
                            • R Offline
                              R Offline
                              rockon209
                              wrote on last edited by rockon209
                              #14

                              @jsulm
                              if I want to use Qthread how i can do it. I havnt used thread till now so dont know how to used it. I read about it but not able to understand.

                              jsulmJ 1 Reply Last reply
                              0
                              • R rockon209

                                @jsulm
                                if I want to use Qthread how i can do it. I havnt used thread till now so dont know how to used it. I read about it but not able to understand.

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

                                @rockon209 Why not just use a QTimer for that?
                                If you really want to use multithreading for that then you should read:
                                https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/
                                http://doc.qt.io/qt-5/thread-basics.html

                                1 Reply Last reply
                                0
                                • R Offline
                                  R Offline
                                  rockon209
                                  wrote on last edited by rockon209
                                  #16

                                  @jsulm
                                  I dont have only one sensors but many sensors are there to measure differnt data then i think it doesnt make any sense to create different timers everytime to get the data from it. Thats why i thought to use thread.

                                  mrjjM 1 Reply Last reply
                                  0
                                  • R rockon209

                                    @jsulm
                                    I dont have only one sensors but many sensors are there to measure differnt data then i think it doesnt make any sense to create different timers everytime to get the data from it. Thats why i thought to use thread.

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @rockon209
                                    There would be nothing to stop from reusing a timer. If you fear you will get too many.
                                    If your design can work with 1 thread, then it can also work with one timer.

                                    How many sensors are we talking about?

                                    We have a system running where it uses QTimer. I think we use around 60 most of the time and have seen
                                    no issue so far.

                                    1 Reply Last reply
                                    2
                                    • R Offline
                                      R Offline
                                      rockon209
                                      wrote on last edited by
                                      #18

                                      @mrjj
                                      i am using around 10 sensors so may be i will need around 8 timers to get the data from them. I dont know which one is the optimum solution. Thats why i started the topic. But if you say that 60 timers are also working fine then i think i will go for timers

                                      J.HilkJ jsulmJ 2 Replies Last reply
                                      0
                                      • R rockon209

                                        @mrjj
                                        i am using around 10 sensors so may be i will need around 8 timers to get the data from them. I dont know which one is the optimum solution. Thats why i started the topic. But if you say that 60 timers are also working fine then i think i will go for timers

                                        J.HilkJ Online
                                        J.HilkJ Online
                                        J.Hilk
                                        Moderators
                                        wrote on last edited by
                                        #19

                                        @rockon209 how exactly to do communicate with your sensors? QIODevice, a file that is written, serial port, bluetooth, vendor specific library etc. Maby theres a prefabricated way/Signal that you can use as a notifier for new data available.


                                        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
                                        • R rockon209

                                          @mrjj
                                          i am using around 10 sensors so may be i will need around 8 timers to get the data from them. I dont know which one is the optimum solution. Thats why i started the topic. But if you say that 60 timers are also working fine then i think i will go for timers

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

                                          @rockon209 How many timers you need depends on how you read all these sensors. If you read all of them at the same frequency then one timer is enough.

                                          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