Connect error

Started by CatalinNic, 22 March 2020, 11:38:23

CatalinNic

I have this test function with tgui::EditBox::Ptr as parameter in a separate cpp file
Code (cpp) Select

void test(tgui::EditBox::Ptr Editbox)
{
    Editbox->connect("clicked", []{}); // error
}

And the error produced is:
Code (none) Select

/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?

texus

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

CatalinNic

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?

texus

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.