Results 1 to 13 of 13

Thread: QThread communicate threadsafe

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2015
    Posts
    67

    Default QThread communicate threadsafe

    I know it's not threadsafe to call a function of another thread in Mainthread. Is it allowed to call a signal form another thread without any problems? Lets say this code is in MainWindow:
    Qt Code:
    1. MainWindow.cpp
    2. thread->moveTOThread(obj);
    3. emit obj->Signal();
    To copy to clipboard, switch view to plain text mode 

    or is this the way to go:
    Qt Code:
    1. Obj.h
    2. signals:
    3. void testSignal();
    4. public slots:
    5. void Func();
    6.  
    7. MainWindow.h
    8. void testSignal();
    9.  
    10. MainWindow.cpp
    11. thread->moveTOThread(obj);
    12. connect(this,SIGNAL(testSignal()),obj,SIGNAL(testSignal()));
    13. emit testSignal();
    14.  
    15. Obj.cpp
    16. connect(this,SIGNAL(testSignal()),this,SLOT(Func()));
    To copy to clipboard, switch view to plain text mode 
    thank you
    Last edited by Ini; 1st June 2016 at 22:56.

Similar Threads

  1. Replies: 1
    Last Post: 4th October 2012, 14:49
  2. Replies: 5
    Last Post: 24th February 2012, 06:49
  3. Replies: 3
    Last Post: 20th September 2011, 20:13
  4. How to communicate between two forms
    By iamjayanth in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2009, 08:17
  5. How to communicate between two different exe
    By Lele in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2006, 13:02

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.