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. Facing problem in use of QtConcurrent.
Forum Updated to NodeBB v4.3 + New Features

Facing problem in use of QtConcurrent.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.0k 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.
  • M Offline
    M Offline
    mady
    wrote on last edited by
    #1

    I wanted to run a function in different thread. I am using QtConcurrent but facing some problem, though I am not sure whether I should use QtConcurrent for the requirement or not.
    @
    bool fun(bool f)
    {
    if (f==true)flag = true;
    return flag;
    }

    void test()
    {
    QtConcurrent::run(fun, true);
    }

    // calling test() in main()
    @

    Execution control is going into trans state. I put a break point into fun() but it never gets hit.
    If I put a wait into test() such a way, so that fun() execute first then only test() gets end, then things go correct.

    It seems since test() is creating new thread to run fun() and completed its execution, so created thread is also gets killed because of that control is going into trans state.
    Please correct me.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      It is not clear to me what the problem is, but you are launching a function on a thread and are not evaluating any result. What are expecting this to be? Also please note that the documentation states that:

      bq. Note that the function may not run immediately; the function will only be run when a thread is available.

      So maybe your application exits before fun has a chance to run?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mady
        wrote on last edited by
        #3

        It seems like we are not allowed to call member function of a class in QtConcurrent::run(). If it is possible please let me know how to call it.
        Basically I have a class which has two functions wanted to run one in different thread from 2nd. Code that I want will be like below,
        @class test
        {
        ....
        void fun();
        void funDiffthrd();
        };

        void test::fun()
        {
        QtConcurrent::run(funDiffthrd); // wanted to acheive this.
        }@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkoskim
          wrote on last edited by
          #4

          Well, I have use QtConcurrent successfully to scan directory tree and place findings to a list. The call looks following ("projects" is instance of moe::ProjectDB):

          [code]
          QtConcurrent::run(&projects, &moe::ProjectDB::populate)
          [/code]

          [url=https://gitorious.org/moe/moe/blobs/master/moeqt/sources/prjmgr/moeProjectView.cpp#line84](Source: moeProjectView.cpp, line 84)[/url].

          http://mkoskim.wordpress.com
          http://mkoskim.drivehq.com
          http://mkoskim.deviantart.com

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            I guess you have to specify the instance on which the method has to be called.

            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