Results 1 to 13 of 13

Thread: [QT4] threads, signals, and slots, please help.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT4] threads, signals, and slots, please help.

    Quote Originally Posted by ucntcme
    Since I wanted it to, naturally.

    Actually, I was mislead by statements (elsewhere) that emit was "just a decoration for the programmer", that the signal was still "just a function call".
    It is (usually) a function call. But! What happens if there are two or more slots connected to a signal? Return value of which of them should then be returned?

    As soon as I figure out just what you mean, I'm sure I'll try it.
    I mean to pass a pointer or reference of the object which is to deliver some information to the other one. This way you'll be able to call the method directly on a single object, without signal/slot mechanism:

    Qt Code:
    1. struct aaa {
    2. int action(someclass &);
    3. };
    4.  
    5. class bbb {
    6. public:
    7. void registerDeliverer(aaa *a){ m_ad = a; }
    8. void do_something();
    9. private:
    10. aaa *m_ad;
    11. }
    12.  
    13. void bbb::do_something(){
    14. //...
    15. if(!m_ad)
    16. return;
    17. int act = m_ad->action(); // fetch an int from registered object
    18. //...
    19. }
    20. //...
    21. aaa action_deliverer;
    22. bbb obj;
    23. //...
    24. obj->registerDeliverer(&action_deliverer);
    25. //...
    26. obj->do_something();
    27. //...
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: [QT4] threads, signals, and slots, please help.

    Quote Originally Posted by wysota
    It is (usually) a function call. But! What happens if there are two or more slots connected to a signal? Return value of which of them should then be returned?
    Well obviously the only one I am interested in!

    Seriously though, that makes sense explained that way.
    Perhaps it would be nice if a warning/error was issued at compile time if a signal was declared as anything other than void? As a newbie that would make some sense to me, and would have alerted me to the head-banging route I was travelling upon.


    Quote Originally Posted by wysota
    I mean to pass a pointer or reference of the object which is to deliver some information to the other one. This way you'll be able to call the method directly on a single object, without signal/slot mechanism:

    Qt Code:
    1. struct aaa {
    2. int action(someclass &);
    3. };
    4.  
    5. class bbb {
    6. public:
    7. void registerDeliverer(aaa *a){ m_ad = a; }
    8. void do_something();
    9. private:
    10. aaa *m_ad;
    11. }
    12.  
    13. void bbb::do_something(){
    14. //...
    15. if(!m_ad)
    16. return;
    17. int act = m_ad->action(); // fetch an int from registered object
    18. //...
    19. }
    20. //...
    21. aaa action_deliverer;
    22. bbb obj;
    23. //...
    24. obj->registerDeliverer(&action_deliverer);
    25. //...
    26. obj->do_something();
    27. //...
    To copy to clipboard, switch view to plain text mode 

    I suspected that was what you meant, and had begun working on that. Of course, I've done it wrong and get segfaults, but I'm sure it's not a Qt related segfault, rather programmer naivete. Some of it I just *have* to bang away at until I get it. But then again, once I get it, I've got it. Know what I mean?


    But one quick question on the above ... what is "someclass" representing?
    --
    The Real Bill

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT4] threads, signals, and slots, please help.

    Quote Originally Posted by ucntcme
    Perhaps it would be nice if a warning/error was issued at compile time if a signal was declared as anything other than void? As a newbie that would make some sense to me, and would have alerted me to the head-banging route I was travelling upon.
    No, because slots are regular methods, just with additional capabilities. You can invoke them as normal methods and use their return values as usual.

    But one quick question on the above ... what is "someclass" representing?
    Some data which is processed by "action" method... That's just an example, nothing specific.

  4. #4
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: [QT4] threads, signals, and slots, please help.

    Quote Originally Posted by wysota
    No, because slots are regular methods, just with additional capabilities. You can invoke them as normal methods and use their return values as usual.
    Well it was a nice thought anyway.

    Quote Originally Posted by wysota
    Some data which is processed by "action" method... That's just an example, nothing specific.
    Well I finally found the route out of segfault land (a nap can do wonders ) and it is all working perfectly. Thanks again!
    --
    The Real Bill

Similar Threads

  1. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 09:06
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  4. Signals and Slots Across Threads
    By themusicalguy in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 11:16
  5. Connecting signals & slots across different threads
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 12:40

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.