v0.8-dev - Passing custom parameters
« 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?

*

texus

  • *****
  • 1254
    • View Profile
    • Texus's Blog
Re: v0.8-dev - Passing custom parameters
« Reply #1 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");

Re: v0.8-dev - Passing custom parameters
« Reply #2 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

*

texus

  • *****
  • 1254
    • View Profile
    • Texus's Blog
Re: v0.8-dev - Passing custom parameters
« Reply #3 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?
« Last Edit: 16 May 2018, 17:55:08 by texus »