TGUI Forum

General Category => Help requests => Topic started by: CatalinNic on 22 March 2020, 11:38:23

Title: Connect error
Post by: CatalinNic on 22 March 2020, 11:38:23
I have this test function with tgui::EditBox::Ptr as parameter in a separate cpp file
void test(tgui::EditBox::Ptr Editbox)
{
    Editbox->connect("clicked", []{}); // error
}

And the error produced is:
/usr/include/TGUI/Signal.hpp:863:22: error: ‘unsigned int tgui::SignalWidgetBase::connect(std::string, Func&&, const BoundArgs& ...) [with Func = test(tgui::EditBox::Ptr)::<lambda()>; BoundArgs = {}; std::string = std::__cxx11::basic_string<char>]’, declared using local type ‘test(tgui::EditBox::Ptr)::<lambda()>’, is used but never defined [-fpermissive]
  863 |         unsigned int connect(std::string signalName, Func&& handler, const BoundArgs&... args);
      |                      ^~~~~~~
/usr/include/TGUI/Signal.hpp:863:22: warning: ‘unsigned int tgui::SignalWidgetBase::connect(std::string, Func&&, const BoundArgs& ...) [with Func = test(tgui::EditBox::Ptr)::<lambda()>; BoundArgs = {}]’ used but never defined
Why it does that?
Title: Re: Connect error
Post by: texus on 22 March 2020, 12:49:44
I would guess that SignalImpl.hpp isn't being included. Are you including TGUI.hpp or were you manually including other headers (in which case you also need to include SignalImpl.hpp)?
Title: Re: Connect error
Post by: CatalinNic on 22 March 2020, 13:11:36
i needed to include SignalImplm, however I was pointed to the Signal header, why don't you implemented there and why don't you included as well in the Widget header?
Title: Re: Connect error
Post by: texus on 22 March 2020, 14:11:23
First of all, the only officially supported way to include TGUI is by including TGUI.hpp. If you chose to include other files directly then you are relying on implementation details and you could run into dependency issues like this.

The files have changed a lot, so I'm not sure if there still is a reason why it remains like this, but there are 2 reasons why the current design might have been chosen:
- To improve compilation speed. Lots of templates can slow down compilation, so it might be beneficial to only include them when needed instead of including them in a file that is included by practically every source file (like Widget.hpp). This of course only affects compiling TGUI itself as in your own code you need to include the signal header anyway, plus the performance difference might not be noticeable.
- To fix a circular dependency. Widget uses Signal, but Signal also uses Widget. Looking at the code, this doesn't seem to be an issue as SignalImpl uses shared_ptr<Widget> instead of Widget::Ptr, so that it doesn't need to include Widget.hpp. But it could have been the reason why the signal code was originally split into 2 files.