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. Text box is not refreshing content on window.
Qt 6.11 is out! See what's new in the release blog

Text box is not refreshing content on window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 2.0k 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.
  • J jenya7

    @jsulm said in Text box is not refreshing on window.:

    @jenya7 said in Text box is not refreshing on window.:

    But if m_sensor.DiscoverConcurrent runs - it blocks the text box and I don't see any prints

    Sounds like m_sensor.DiscoverConcurrent is a blocking call and does NOT run concurrently.

    May be.

    uint32_t SENSOR::DiscoverConcurrent(uint8_t min, uint8_t max, uint8_t mode)
    {
        QFuture<uint32_t> future;
    
         rt_params.service = 1;
    
         switch (mode)
         {
             case SYS_DISC_MODE_ALL:
                 future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexAll, max);
             break;
             case SYS_DISC_MODE_RANGE:
                   future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexRange, min, max);
             break;
             case SYS_DISC_MODE_FILE:
                   future = QtConcurrent::run(this, &SENSOR::DiscoverByList);
             break;
         }
    
        rt_params.service = 0;
    
        return future;
    }
    

    At least I try. I get no exceptions or run time messages. How can I be sure another thread was created?
    The function is executed - I see result on finish.

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

    @jenya7
    I assume

    uint32_t SENSOR::DiscoverConcurrent(uint8_t min, uint8_t max, uint8_t mode)
    {
        QFuture<uint32_t> future;
    ....
       return future;
    }
    

    does an implicit call to result() to return the uint32_t value,

    which will wait until the concurrent has run its course.

    Congratulations, you turned it back into a synchronous program :P

    give the QFuture object to an QFutureWatcher instance and listen to the finished signal there.


    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.

    jsulmJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @jenya7
      I assume

      uint32_t SENSOR::DiscoverConcurrent(uint8_t min, uint8_t max, uint8_t mode)
      {
          QFuture<uint32_t> future;
      ....
         return future;
      }
      

      does an implicit call to result() to return the uint32_t value,

      which will wait until the concurrent has run its course.

      Congratulations, you turned it back into a synchronous program :P

      give the QFuture object to an QFutureWatcher instance and listen to the finished signal there.

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

      @J-Hilk said in Text box is not refreshing content on window.:

      does an implicit call to result() to return the uint32_t value

      Yes, this is also what I think is happeneing, but can't find anything related to this in QFuture documentation.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J.HilkJ 1 Reply Last reply
      0
      • jsulmJ jsulm

        @J-Hilk said in Text box is not refreshing content on window.:

        does an implicit call to result() to return the uint32_t value

        Yes, this is also what I think is happeneing, but can't find anything related to this in QFuture documentation.

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

        @jsulm probably this one ?

        https://doc.qt.io/qt-5/qfuture.html#operator-T


        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
        2
        • jsulmJ jsulm

          @jenya7 Why is the return type uint32_t and not QFuture<uint32_t>?

          J Offline
          J Offline
          jenya7
          wrote on last edited by
          #8

          @jsulm said in Text box is not refreshing on window.:

          @jenya7 Why is the return type uint32_t and not QFuture<uint32_t>?

          I fixed it. But the issue stays.

          jsulmJ 1 Reply Last reply
          0
          • J jenya7

            @jsulm said in Text box is not refreshing on window.:

            @jenya7 Why is the return type uint32_t and not QFuture<uint32_t>?

            I fixed it. But the issue stays.

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

            @jenya7 said in Text box is not refreshing content on window.:

            I fixed it

            I bet you did not, because discovered variable is still uint32_t, right?
            Please read what @J-Hilk wrote.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • jsulmJ jsulm

              @jenya7 said in Text box is not refreshing content on window.:

              I fixed it

              I bet you did not, because discovered variable is still uint32_t, right?
              Please read what @J-Hilk wrote.

              J Offline
              J Offline
              jenya7
              wrote on last edited by jenya7
              #10

              @jsulm said in Text box is not refreshing content on window.:

              @jenya7 said in Text box is not refreshing content on window.:

              I fixed it

              I bet you did not, because discovered variable is still uint32_t, right?
              Please read what @J-Hilk wrote.

              Now it is
              in main.cpp

              QFuture<uint32_t>  discovered;
              

              in sensor.cpp

              QFuture<uint32_t> SENSOR::DiscoverConcurrent()........
              

              Still the same.

              Wait a minute... SENSOR::DiscoverConcurrent calls

              future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexAll, max);
              

              so SENSOR::DiscoverByIndexAll - should be also QFuture<uint32_t> ?

              well..the problem is only on start up. If I call SENSOR::DiscoverConcurrent() from another place (after return a.exec();) it works good.

              J 1 Reply Last reply
              0
              • J jenya7

                @jsulm said in Text box is not refreshing content on window.:

                @jenya7 said in Text box is not refreshing content on window.:

                I fixed it

                I bet you did not, because discovered variable is still uint32_t, right?
                Please read what @J-Hilk wrote.

                Now it is
                in main.cpp

                QFuture<uint32_t>  discovered;
                

                in sensor.cpp

                QFuture<uint32_t> SENSOR::DiscoverConcurrent()........
                

                Still the same.

                Wait a minute... SENSOR::DiscoverConcurrent calls

                future = QtConcurrent::run(this, &SENSOR::DiscoverByIndexAll, max);
                

                so SENSOR::DiscoverByIndexAll - should be also QFuture<uint32_t> ?

                well..the problem is only on start up. If I call SENSOR::DiscoverConcurrent() from another place (after return a.exec();) it works good.

                J Offline
                J Offline
                jenya7
                wrote on last edited by
                #11

                What if I want to invoke SENSOR::DiscoverConcurrent() after return a.exec();?
                What event to connect?

                QObject::connect(&a, a.???
                
                jsulmJ 1 Reply Last reply
                0
                • J jenya7

                  What if I want to invoke SENSOR::DiscoverConcurrent() after return a.exec();?
                  What event to connect?

                  QObject::connect(&a, a.???
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  @jenya7 said in Text box is not refreshing content on window.:

                  What event to connect?

                  Why do you need an event/signal for that?
                  Just call it after a.exec()...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  J 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @jenya7 said in Text box is not refreshing content on window.:

                    What event to connect?

                    Why do you need an event/signal for that?
                    Just call it after a.exec()...

                    J Offline
                    J Offline
                    jenya7
                    wrote on last edited by jenya7
                    #13

                    @jsulm said in Text box is not refreshing content on window.:

                    @jenya7 said in Text box is not refreshing content on window.:

                    What event to connect?

                    Why do you need an event/signal for that?
                    Just call it after a.exec()...

                    what is "after"?

                    int main(int argc, char *argv[])
                    {
                       ............
                      return a.exec();
                    
                      discovered = m_sensor.DiscoverConcurrent(0, 4, SYS_DISC_MODE_ALL);
                    }
                    

                    code will never be executed.

                    jsulmJ 1 Reply Last reply
                    0
                    • J jenya7

                      @jsulm said in Text box is not refreshing content on window.:

                      @jenya7 said in Text box is not refreshing content on window.:

                      What event to connect?

                      Why do you need an event/signal for that?
                      Just call it after a.exec()...

                      what is "after"?

                      int main(int argc, char *argv[])
                      {
                         ............
                        return a.exec();
                      
                        discovered = m_sensor.DiscoverConcurrent(0, 4, SYS_DISC_MODE_ALL);
                      }
                      

                      code will never be executed.

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

                      @jenya7 said in Text box is not refreshing content on window.:

                      code will never be executed

                      Well, it is really not hard to change this code in a way it does what you want.
                      But I will let this simple exercise to you...

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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