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. passing qtconcurrent
Qt 6.11 is out! See what's new in the release blog

passing qtconcurrent

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k Views 1 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.
  • S Offline
    S Offline
    s002wjh
    wrote on last edited by s002wjh
    #1

    whats the current syntax to pass function within a class and its arguement to qtconcurrent.

    for example

    typedef struct
    {
    QString t1;
    float t2;
    int t3;

    } mystrc;

    class test : public QWidget
    {
    Q_OBJECT

    public:

    void test_func(mystrc *mystrc_ptr);
    }

    class Main_Widget : public QWidget
    {
    Q_OBJECT

    public:

    test *test_ptr;

    }

    Main_Widget::Main_Widget(QWidget *parent){

    mystrc *myst_ptr;
    test_ptr = new test;
    QFuture<void> future = QtConcurrent::run(this->test_ptr, &test::test_func, myst_ptr);

    }

    ?

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

      Hi,

      It's explained here.

      Note that in your code, you are passing a local uninitialised pointer which is likely not a good idea.

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

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        It's explained here.

        Note that in your code, you are passing a local uninitialised pointer which is likely not a good idea.

        S Offline
        S Offline
        s002wjh
        wrote on last edited by s002wjh
        #3

        @SGaist

        if i do this,

        Main_Widget::Main_Widget(QWidget *parent){

        mystrc *myst_ptr;

        test_ptr = new test;

        for(n=0; n<100; n++){
        QFuture<void> future = QtConcurrent::run(this->test_ptr, &test::test_func, myst_ptr);
        }
        }

        does it recognize to create 1 thread for the function or its try to create 100 thread. if its latter how do i run the function repeatly in different thread, with out destroy then recreate the thread etc. basically i like to run the function in 1 thread over and over.

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

          Neither, as explained in the QtConcurrent::run documentation, it's going to use a thread pool to run the 100 task you asking it to run.

          What exactly is your function going to do ? From the little you shared, it looks like you should subclass QThread and re-implement the run function with a breakable infinite loop.

          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