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 create a thread that permanently gives back values

How to create a thread that permanently gives back values

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 830 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.
  • T Offline
    T Offline
    Tomax63
    wrote on last edited by
    #1

    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
    0
    • T Tomax63

      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 Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @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
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        2
        • O Offline
          O Offline
          ollarch
          wrote on last edited by
          #4

          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
          1
          • K koahnig

            @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?

            T Offline
            T Offline
            Tomax63
            wrote on last edited by
            #5

            @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
            0
            • T Tomax63

              @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 Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              @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
              3

              • Login

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