Results 1 to 4 of 4

Thread: Is this a bad nono? Geting the return value from a slot.

  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Platforms
    Windows

    Default Is this a bad nono? Geting the return value from a slot.

    Hi,
    as far as I know there is no way to emit a signal and retrieve the value returned by the matching connected slot (please correct me if I am wrong).
    So, how big a crime is it if i pass a parameter as an "out_value" to the slot, and the slot writes its return value in that "out_value" pointer?

    something like:

    Qt Code:
    1. self.connect( self, SIGNAL("mysignal(param,param)"), self.myslot )
    2.  
    3. self.out_var = {}
    4. emit( SIGNAL( "mysignal(param,param)"), paramval1,self.out_var ) // slot is now executed, and return value
    5. // is written to self.out_var
    6.  
    7. return_value = self.out_var['return']
    To copy to clipboard, switch view to plain text mode 

    and myslot :
    Qt Code:
    1. def myslot(self,param1,param2):
    2.  
    3. param2['return'] = param1+param2;
    4.  
    5. return param2;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2011
    Posts
    239
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60
    Thanks
    4
    Thanked 35 Times in 35 Posts

    Default Re: Is this a bad nono? Geting the return value from a slot.

    Why would that be a crime if it makes sense...

    The "only" problem is that if the application is based on a message passing asynchronous architecture, you may have a problem if you have (through that pointer) a new value appearing somewhere, but no signal to start dealing with it & to noticy the app about it. But there are many situations where it is absolutely ok and good design.

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: Is this a bad nono? Geting the return value from a slot.

    and what if there's two slots connected to that signal?
    IMHO that's a bad idea.

    Wouldn't it be better instead of returning a value, emit a signal with a value and connect it to where you want?

    And you can get return value from a slot using QMetaObject::invokeMethod() but it requires different approach than connecting signal to slot.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Is this a bad nono? Geting the return value from a slot.

    Also dangerous if the sender and receiver are in separate threads.

Similar Threads

  1. slot return type
    By adamatic in forum Qt Programming
    Replies: 13
    Last Post: 4th October 2014, 22:01
  2. Replies: 1
    Last Post: 19th October 2010, 06:08
  3. QGraphicsView I'm not geting output
    By jthacker in forum Qt Programming
    Replies: 4
    Last Post: 29th May 2010, 10:06
  4. Slot with a return value?
    By lalesculiviu in forum Qt Programming
    Replies: 9
    Last Post: 21st December 2009, 07:27
  5. Replies: 12
    Last Post: 14th June 2006, 10:24

Tags for this Thread

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.