Undefined reference to .connect

Started by cpyro, 19 June 2020, 10:43:17

cpyro

Hi, I've been trying to get .connect working, but am having trouble. Partial code below. For more context, the Screen class is a thin wrapper around tgui::Gui, and has methods render() and checkForEvent(). The Controller class is intended to construct Screens.

Code (cpp) Select
    void StartScreenController::constructJoinScreen() {
        auto gui = std::make_shared<tgui::Gui>(*this->_window);

        int win_x = this->_window->getSize().x;
        int win_y = this->_window->getSize().y;

        // Edit boxes
        auto editBox = tgui::EditBox::create();
        editBox->setSize(200, 25);
        editBox->setTextSize(18);
        editBox->setPosition(win_x/2-300, win_y/2);
        editBox->setDefaultText("Enter host IP address...");

        // This line of code below causes an error when uncommented.
        // editBox->connect("ReturnKeyPressed", &StartScreenController::handleEnterHostIpAddress, this);

        gui->add(editBox);

        this->_join_screen = ss::Screen(this->_window, gui, "../resources/images/main_bg.png");
    }

    void StartScreenController::handleEnterHostIpAddress(const sf::String& buttonText) {
        std::cout << "enter host ip game" << std::endl;
    }


This works (edit box appears and you can type in it) when the problematic line of code commented out. When the line is uncommented, I get this error:

Code (none) Select
undefined reference to `unsigned int tgui::SignalWidgetBase::connect<void (ss::StartScreenController::*)(sf::String const&), ss::StartScreenController*>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void (ss::StartScreenController::*&&)(sf::String const&), ss::StartScreenController* const&)'

I don't understand why I get this error; any ideas? I wonder if I have to cast my classes into something more appropriate, but haven't seen that in other examples I've seen online...


texus

Are you including TGUI.hpp or are you including Signal.hpp directly? If you don't include TGUI.hpp then you must also include SignalImpl.hpp

cpyro

I was not including TGUI.hpp! I only had "#include <TGUI/Widgets/EditBox.hpp>". Now it works, thank you!

eugustus

Quote from: texus on 19 June 2020, 12:52:46
Are you including TGUI.hpp or are you including Signal.hpp directly? If you don't include TGUI.hpp then you must also include SignalImpl.hpp

It's good to KNOW!!