0

I've got a FTP application written in c++. Now I'm adding a simple GUI to my project via the Qt plugin for VS2010. The mechanism to connect to the server is very simple. After typing both IP and PORT the connection is stablished and an object is created. This object (from a class I've written) can call several functions such as: ask for the available files on server, download an specific file, etc.

My question is: if that object is created after pressing a button (and calling the function it is linked to) is there any way to return that object? Sure there is but, how and where in the code should it be stored/declared. Here is the code line:

connect(ui.btn_connect,SIGNAL(clicked()),this,SLOT(on_SayConnect()));

How should I call the function "on_SayConnect()" if I want an object to be returned using the connect (SIGNAL/SLOT) syntax? Thank you in advance.

karl71
  • 1,082
  • 2
  • 18
  • 29
  • Where do you want to return the object to? – Frank Osterfeld Nov 16 '13 at 19:28
  • That is why I'm asking this question. I need to pass that returned object to other functions (when called, after clicking on a button) but I don't know where should it be declared or stored. – karl71 Nov 16 '13 at 19:50
  • 1
    on_SayConnect() should pass the created object wherever it's supposed to go. That should be independent of how on_SayConnect() was called (via signal, or otherwise). – Frank Osterfeld Nov 16 '13 at 19:55
  • What do you think should happen if two slots are connected to the signal? Which one's return value is the "real" one that should actually be returned to where the signal was emitted? – jalf Nov 17 '13 at 14:54

1 Answers1

0

There's no good way to return values using the connect method. If your goal is to have the this object (I don't think you actually gave it a name) send a value/object to other parts of the system, you could have the on_SayConnect slot emit a signal with the desired value. Any other objects that need to receive that value should implement and connect the proper slot to do so.

Jacob Robbins
  • 1,860
  • 14
  • 16