Listbox signals

Started by roccio, 10 May 2018, 16:31:37


I have some problems going from 0.7 to 0.8 regarding the signals and in particular the old connectEx functions.
In example I had a function called when an item in a list box is selected. The function passed to the old connectEx used a parameter Callback that reported the selectedItemId.

How can I get the same with the new signal system?

Sorry for the noob question, but I have not found any tutorial...


It's badly documented, but the ItemSelected trigger has 1 or 2 strings as optional parameters. So you can just add an sf::String (or std::string, with or without const&) parameter to the callback function then it will be called with the selected item. If items in the list box aren't unique then the extra string parameter will contain the id (optional second parameter passed to addItem).

Code (cpp) Select

void f1() { std::cout << "Item selected" << std::endl; }
void f2(const sf::String& item) { std::cout << "Item selected: " << item.toAnsiString() << std::endl; }
void f3(std::string item, std::string id) { std::cout << "Item selected: " << item << " with id: " << id << std::endl; }
listBox->connect("ItemSelected", &f1);
listBox->connect("ItemSelected", &f2);
listBox->connect("ItemSelected", &f3);


Ok, thank, this worked perfectly!


Hi again, I have a problem with the listbox, maybe I'm doing something wrong. My program crashes when I call listbox->removeAllItems() and points to ListBox.cpp line 916 (   m_items[m_hoveringItem].setColor(m_textColorCached);)

I'm using VC 2015 and shared libs:

void Test()
sf::RenderWindow window({ 600,600 }, "test");
tgui::Gui gui(window);
tgui::ListBox::Ptr listbox = tgui::ListBox::create();


listbox->connect("MousePressed", [=]() { listbox->removeAllItems(); });

while (window.isOpen())
sf::Event event;
while (window.pollEvent(event))
if (event.type == sf::Event::Closed)




This is the problem with developing on linux, it just runs no matter what happens :). My pc happily continues running without issues even after invalid memory was accessed like in this code. Although I couldn't reproduce it here, I think I know what the issue was and it should be fixed in the latest version.