button->connect member functions

Started by Simon, 24 March 2019, 16:54:34

Simon

Hi, I'm creating a GUI for an application used to create random level layouts.

I'm trying to connect a button using member functions and member variables. I tried following some other topics and the introduction to signals post but to to avail.

Here is some code to show what I'm trying to do:
   m_buttonGenerateRW->connect("pressed", &App::generateRW,
&instance,
m_ebMaxWalkers,
m_ebFillPercentage,
m_ebChanceToChangeDirection,
m_ebChanceStartAlive,
m_ebChanceToDestroyWalker,
m_ebChanceToSpawnNewWalker);



m_buttonGenerateCA->connect("pressed", &App::generateCA,
&instance,
m_ebNumSimulationSteps,
m_ebBirthLimit,
m_ebDeathLimit,
m_ebChanceStartAlive);


Any help would be greatly appreciated,

Simon

texus

Can you show the declarations of generateRW, generateCA, instance and the other parameters you are passing?

Simon

Yes of course


App instance;



void generateRW(tgui::EditBox::Ptr ebMaxWalkers,
tgui::EditBox::Ptr ebFillPercentage,
tgui::EditBox::Ptr ebChanceToChangeDirection,
tgui::EditBox::Ptr ebChanceToDestroyWalker,
tgui::EditBox::Ptr ebChanceToSpawnNewWalker);



void generateCA(tgui::EditBox::Ptr ebNumSimulationSteps,
tgui::EditBox::Ptr ebBirthLimit,
tgui::EditBox::Ptr ebDeathLimit,
tgui::EditBox::Ptr ebChanceStartAlive);


Simon

texus

The parameters for generateRW don't match, in the connect function you pass one parameter too much, the m_ebChanceStartAlive.

The generateCA line looks fine, assuming the edit boxes are declared like this in the App class:
Code (cpp) Select
tgui::EditBox::Ptr m_ebNumSimulationSteps;

Can you show the full errors you get on the m_buttonGenerateCA->connect call?

Simon

Ah, the error was what you caught with the extra parameter while connecting the buttonGenerateRW, seems to work fine now.
Thanks for your help and for creating a great tool for making GUIs.

Simon.