PDA

View Full Version : Signals in libraries



tuli
17th October 2018, 07:51
Hi,


edit: dont bother, solved


my project consists of two parts: One GUI-project and one library that exposes an API consumed by the GUI app. Both of them are qtcreator projects. Everything works fine without signals and slots.


But now I have added a class with a signal to the library-project. The signal is emitted in one of the APIs exposed to the GUI. But even when there are no slots connected to that signal, my Application craps out and crashes!
Yes, the app launches but when I press the button that triggers the signal, it executes right up to the "emit" and then crashes at runtime!




.../qtgui: symbol lookup error: .../qtgui/../core/libcore.so.1: undefined symbol: _ZN5xtest4testE7myevent


Here is the code, some_exposed_api() is called from the GUI:


bool LIBLIBSHARED_EXPORT some_exposed_api()
{
xtest tt;
tt.test_emit();
}

...

class myevent
{
public:
myevent() = default;

uint xyz = 0;

};
Q_DECLARE_METATYPE(myevent);


class xtest : public QObject
{
public:
xtest()
{
qRegisterMetaType<myevent>("myevent");
}

void test_emit()
{
myevent x;
emit test(x); //crash!
}
signals:
void test(myevent x);
};



Why does it crash? I dont get it. It's all loaded into one process at runtime.

Alright, of course minutes after posting I realize the mistake: the goddamn Q_OBJECT macro was missing .. wasnt I supposed to get a big fat warning in qtcreator when that happens ...