Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6844039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:19:37+00:00 2026-05-27T00:19:37+00:00

When do we use each of this function calls in a threaded application. given

  • 0

When do we use each of this function calls in a threaded application.
given two functions fun1() and fun2() defined in the same class dealing with read/write of data into buffers(queue operation). to achieve multi-threading to these. we would have to run the two functions in a separate thread. now lets say the first function read is called at the start of its thread.

is it better to use moveTothread ( second thread)for
function write at the start of the first
functions thread

Or

define the second function in a new
thread class and call that thread at
the start of the first thread.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:19:38+00:00Added an answer on May 27, 2026 at 12:19 am

    Using moveToThread we can change the thread affinity of an object. What the OP asks is how we can run two functions of the same class in different threads.

    Let class A and two functions f1 and f2

    class A
    {
    public:
        void f1();
        void f2(int i); 
        void run(); // shows how we can trigger f1 and f2 in different threads
    }
    

    Qt already provided a class for running functions in different threads and it is called QtConcurrentRun

    The QtConcurrent::run() function runs a function in a separate thread.
    The return value of the function is made available through the QFuture
    API.

    The function that is triggered can be either an external function or a member function. So in our case if we wanted from the object itself to start f1 and f2 in different threads we could do the following in run()

    void run()
    {
       // QFuture<void> because f1 is void 
       QFuture<void> future1 = QtConcurrent::run(this, &A::f1);
       int k = 5; // Concurrent run with arguments
       QFuture<void> future2 = QtConcurrent::run(this, &A::f2, k);
    } 
    

    similarly you could execute any public function of any class concurrently, eg

    QImage image = ...;
    QFuture<void> future = QtConcurrent::run(image, &QImage::invertPixels, QImage::InvertRgba);
    
    A a;
    QFuture<void> future1 = QtConcurrent::run(A, &A::f1);
    

    Notice the difference between the two calls:

    QtConcurrent::run() also accepts pointers to member functions. The
    first argument must be either a const reference or a pointer to an
    instance of the class. Passing by const reference is useful when
    calling const member functions; passing by pointer is useful for
    calling non-const member functions that modify the instance.

    In order to check when a concurrently executed function has finished you should use a QFutureWatcher.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used to use this script for jquery email obfuscation: $(.replaceAt).replaceWith(@); $(.obfuscate).each(function () {
I'm trying to use a user-defined function in XSLT that repeatedly calls the value
I have stored 6 records in mysql db,when i use this code each of
i have this crazy label for each time i create a migration that use
What's the difference between the two and when should I use each: <person> <firstname>Joe</firstname>
I'm building a multi-threaded service application in Delphi XE2. Each thread serves its own
I use such code to pass arguments to event handler functions. But, in this
char *strtok(char *s1, const char *s2) repeated calls to this function break string s1
When should I use each?
I'm interested in knowing how many developers use each of the major languages/platforms, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.