TGUI Forum

General Category => Help requests => Topic started by: roccio on 30 January 2020, 08:56:08

Title: Combobox signal
Post by: roccio on 30 January 2020, 08:56:08
Hi,
I have a combox and I want to connect a function on itemselected that pass the index of the selected item and not the text.

void ChangeColor(int index) { std::cout << index; std::endl;}

...

g_comboColor->connect("ItemSelected", ChangeColor);


This compiles well, but when I run the code I get an exception in SignalImpl.hll

const std::size_t offset = (sizeof...(UnboundArgs) > 0) ? signal.validateTypes({typeid(UnboundArgs)...}) : 0; (line 157)

What am I missing?
Title: Re: Combobox signal
Post by: Kvaz1r on 30 January 2020, 09:16:10
Could you provide minimal reproducible example?
Title: Re: Combobox signal
Post by: roccio on 30 January 2020, 09:22:36
With this I get no exception, but the value printed are not the one expected.

Code: [Select]
void ChangeColor(int val)
{
std::cout << val << std::endl;
}

int main()
{
sf::RenderWindow window(sf::VideoMode(SCREEN_W, SCREEN_H), "Aircraft configurator", sf::Style::Close);
window.setIcon(icon_image.width, icon_image.height, icon_image.pixel_data);

// init gui
tgui::Gui gui;
gui.setTarget(window);

tgui::ComboBox::Ptr combo = tgui::ComboBox::create();
combo->setPosition(100, 100);
combo->addItem("One");
combo->addItem("Two");
combo->connect("ItemSelected", ChangeColor);
gui.add(combo);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed: window.close(); break;
}

gui.handleEvent(event);
}

window.clear(sf::Color::White);

gui.draw();

window.display();
}

return 0;
}
Title: Re: Combobox signal
Post by: Kvaz1r on 30 January 2020, 09:31:45
Code works well for me.
Could you rebuild TGUI with current master and check it again? This commit (https://github.com/texus/TGUI/commit/0f632f492c05e5b66bfbce5b1586db826673af0c) seems related to your issue.
Title: Re: Combobox signal
Post by: roccio on 30 January 2020, 09:33:22
Will try asap. I have just downloaded the last binary from the Download section (0.8.6).

Thank you