Results 1 to 4 of 4

Thread: Call method of Object in different Thread

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Call method of Object in different Thread

    No, a method (more generally any function) is always executed in the same thread that called it. This has nothing to do with them being methods of QObjects who happen to have a notion of thread affinity.

    However, Qt contains some features allowing a programmer to easily trigger the execution of a method of a QObject in the thread controlling this QObject (which may be distinct from the current thread) provided this thread runs an event loop. One such way is to use signal-slot connections. Another way (which may be simpler in your case) is to use QMetaObject::invokeMethod().

    In any case I strongly recommend you read the docs on signals/slots across threads and QObject's thread affinity.

    I do not understand what you mean by "lock the member method with QMutex". All I can say is that QMutex is useful when you need to serialize access to a resource shared among sevaral threads.

  2. The following user says thank you to yeye_olive for this useful post:

    Qiieha (26th July 2012)

Similar Threads

  1. How to call a function in the mother object from a child object?
    By Momergil in forum General Programming
    Replies: 4
    Last Post: 18th December 2011, 15:49
  2. C++ method call
    By ^NyAw^ in forum General Programming
    Replies: 4
    Last Post: 19th November 2011, 12:19
  3. None-GUI thread call widget method cause error
    By luochen601 in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2010, 05:39
  4. Replies: 6
    Last Post: 15th April 2010, 20:02
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.