Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved How to create a thread that permanently gives back values

    General and Desktop
    4
    6
    505
    Loading More Posts
    • 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.
    • T
      Tomax63 last edited by

      Hello all
      I have a function that processes some values and returns them in an array so i can write them into two fields in my UI.

      QVector<QString> WindowObject::function_a(QVector<QString> values_in){
          QVector<QString> values_out; 
          values_out[0] = modify(values_in[0]);
          values_out[1] = modify(values_in[1]);
          return values_out;
      }
      

      in Main:

      QVector<QString> get_values;
      get_values = function_a(QV_values);
      ui->field_1.set_text(get_values[0]);
      ui->field_2.set_text(get_values[1]);
      

      Now I want to generate a thread that updates the two fields permanently whe I start the thread and stops updating when I stop the thread. I read about working threads but do not seem to understand it.
      Can anybody help me with that?

      Thomas

      K 1 Reply Last reply Reply Quote 0
      • K
        koahnig @Tomax63 last edited by

        @Tomax63

        Hi and welcome todevnet forum

        Probably the easiest is to follow that guide and add an additional signal sending results as required.

        Are you already familiar with Qt's signal and slot scheme?

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

        T 1 Reply Last reply Reply Quote 3
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi and welcome to devnet,

          How are you modifying this array ?
          How long does it take ?
          Where does the input come from ?

          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 Reply Quote 2
          • O
            ollarch last edited by

            Hi,

            Look at Mandelbrot example. You only have to override the "run()" method. Also you can use a boolean variable to let the loop exit(and the thread will exit too).

            1 Reply Last reply Reply Quote 1
            • T
              Tomax63 @koahnig last edited by

              @koahnig
              Hello

              I have NO IDEA about slots and signals. I am new to C++ and Qt.

              I generated an object representing a window with two lineEdits.Now I want to start a thread that updates those 2 lineEdits with values that are retrieved from a hardware device via USB (the reading off the device already works, but only each time I start it by clicking a button).

              Now I want to start a thread that does the updating automatically.

              Thomas

              K 1 Reply Last reply Reply Quote 0
              • K
                koahnig @Tomax63 last edited by

                @Tomax63

                Probably you need to post some of your code.

                When you are using a button and clicking on it is retrieving the information from a usb, you might already use a (signal-)slot functionality.

                When you have done it in a Qt way you are probably only required to substitute the button trigger with a QTimer pulling the information on a regular time interval. However,that is a sort of a wild guess based on my experience and the way I would do.

                Best is posting the declaration of your class and at the routine doing the pulling of information and display.

                Did you use one of Qt templates to start off?

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

                1 Reply Last reply Reply Quote 3
                • First post
                  Last post