Undefined reference to .connect

  • 2 Replies
Undefined reference to .connect
« on: 19 June 2020, 10:43:17 »
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.

    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->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);


        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:

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...



  • *****
  • 1569
    • View Profile
    • Texus's Blog
Re: Undefined reference to .connect
« Reply #1 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

Re: Undefined reference to .connect
« Reply #2 on: 19 June 2020, 13:36:35 »
I was not including TGUI.hpp! I only had "#include <TGUI/Widgets/EditBox.hpp>". Now it works, thank you!