Results 1 to 8 of 8

Thread: One signal more slots

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: One signal more slots

    I can't do this cause the object lives in different threads.

    I've something like this:
    Qt Code:
    1. class Manager : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. signals:
    6. void invokeObjMethod(int);
    7.  
    8. private:
    9. void initManager(){
    10.  
    11. for ( int idx = 0 ; idx < n; idx++){
    12. QThread * th = new QThread(this);
    13. MyObject * obj = new MyObject(idx);
    14. connect(this,SIGNAL(invokeObjMethod(int)),obj,SLOT(doSomething(int)));
    15. obj->moveToThread(th);
    16. th->start();
    17. }
    18. }
    19. }
    20.  
    21. class MyObject : public QObject
    22. {
    23. Q_OBJECT
    24. public:
    25. MyObject(int idx, QObject * parent = 0)
    26. :QObject(parent),
    27. m_index(idx){}
    28.  
    29. private:
    30. int m_index;
    31.  
    32. public slots:
    33. void doSomething(int idx){
    34. if ( idx != m_index)
    35. return;
    36.  
    37. ...do Something ...
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

    When the manager emit the signal invokeObjMethod(int) all the objects invoke their slot but only one do something.
    I want to know if this is the right way or there are other best solu
    Last edited by paolom; 31st July 2012 at 09:40.

Similar Threads

  1. Signal/Slots, Where can i use it?
    By Tio in forum Newbie
    Replies: 2
    Last Post: 25th May 2010, 01:36
  2. Signal and Slots
    By waynew in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 03:50
  3. add signal/slots at runtime?
    By oc2k1 in forum Qt Programming
    Replies: 10
    Last Post: 15th June 2009, 19:52
  4. signal and slots
    By vermarajeev in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2007, 08:31
  5. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 10:10

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.