TGUI Forum

General Category => Help requests => Topic started by: roccio on 15 May 2018, 13:57:51

Title: v0.8-dev - Passing custom parameters
Post by: roccio on 15 May 2018, 13:57:51
Hello, I have not understand how to correctly pass custom parameters is signal functions.
In my case I have a class member function that has 1 parameter as input

Code: [Select]
void PanelClient::windowChooseKey(const std::string& textbox)
I connect this function to a button press

Code: [Select]
button->connect("pressed", &PanelClient::windowChooseKey, "txtWindowShowHideKey", this);
but I am not able to compile.

What's the correct way of doing this?
Title: Re: v0.8-dev - Passing custom parameters
Post by: texus on 15 May 2018, 17:48:47
The 'this' parameter is always the first one of a member function, so the line should be
button->connect("pressed", &PanelClient::windowChooseKey, this, "txtWindowShowHideKey");
Title: Re: v0.8-dev - Passing custom parameters
Post by: roccio on 16 May 2018, 09:39:28
Still have the same error (Visual C++ 2015 reports error C2075).

Code: [Select]
class PanelClient
{
private:
    void windowChooseKey(const std::string& textbox)
   {
        std::cout << "Here I am" << std::endl;
   }
}

 later in code...

Code: [Select]
button->connect("pressed", &PanelClient::windowChooseKey, this, "txtWindowShowKey" );

When compiling error C2075
Title: Re: v0.8-dev - Passing custom parameters
Post by: texus on 16 May 2018, 17:52:42
The 'this' parameter has to be a pointer to the class instance (the value that 'this' would have when using 'this' inside the callback function itself). So you have to pass something else when the connect call is not being called from inside the PanelClient class.
PanelClient client;
button->connect("pressed", &PanelClient::windowChooseKey, &client, "txtWindowShowKey" );

Edit: If that isn't the problem then could you show the build output? I just googled C2075 and it seems like it has nothing to do with this line itself. Are you using VS2015 update 2 or higher?