Unsolved new connect syntax, signal not found (class from linked library)
-
Hi,
I've a Qt project with:
a library:
# .pro [...] TARGET = qb_library TEMPLATE = lib [...]
and the main project:
# .pro [...] TARGET = my_program TEMPLATE = app [...] LIBS += -L$$DESTDIR -lqb_library INCLUDEPATH += ../qb_library DEPENDPATH += ../qb_library [...]
In the library project I have this class:
// .h #include <QObject> class TestConn3 : public QObject { Q_OBJECT public: explicit TestConn3(QObject *parent = 0); void testSignal3Emission(); signals: void testSignal3(); }; // .cpp TestConn3::TestConn3(QObject *parent) : QObject(parent) {} void TestConn3::testSignal3Emission() { emit testSignal3(); }
and in the program project I have:
// .h #include <QObject> class TestCaller : public QObject { Q_OBJECT public: explicit TestCaller(QObject *parent = 0); private slots: void testSlot(); }; // .cpp #include "testcaller.h" #include <QDebug> #include <testconn3.h> TestCaller::TestCaller(QObject *parent) : QObject(parent) { TestConn3 tc3; connect(&tc3, &TestConn3::testSignal3, []() { qDebug() << "testSignal3 lambda"; }); connect(&tc3, SIGNAL(testSignal3()), SLOT(testSlot())); tc3.testSignal3Emission(); } void TestCaller::testSlot() { qDebug() << "testSignal3 slot"; }
I simply execute the code with:
TestCaller tc;
from a MainWindow method.
The output I get is:
QObject::connect: signal not found in TestConn3 testSignal3 slot
So is only the "new syntax" for the connect that's not working.
I tried to put the TestConn3 class directly inside the program project (simply copied the .h and .cpp file and added to .pro) and the connection with the lambda works fine so I suppose it's something related to the library.I'm using Qt 5.4.2 with MinGW 32bit on Windows. (The posted code is only for testing of course. I'm actively developing a quite large project since many years now with around 1k clients around Italy and we could have issues to update the Qt platform so for now I'm sticking with 5.4).
What I'm doing wrong?
Thanks!
(it's my first post here btw so I hope i posted it correctly) -
Hi @pasiaNos-0
The output I get is:
QObject::connect: signal not found in TestConn3
testSignal3 slotThis is at runtime, correct?
Then it cannot be from the new syntax. The new syntax generates compiler errors. Only the old syntax is evaluated at runtime and generates such messages.
Regards
-
@aha_1980 said in new connect syntax, signal not found (class from linked library):
Then it cannot be from the new syntax.
It can, see QObject::connectImpl(). I would guess the problem comes from the fact that the class is not exported - but the I wonder how the code above should work at all then...
-
@aha_1980 @Christian-Ehrlicher
Yes it is the runtime output.
In any case, in the production code I have the project set up with the main project (with subdirs with .pri files) and the external library like in the example and it has always worked (with old syntax connections). For a new functionality I was testing the lambda connection and I came across this problem. For what I need I can workaround the issue with a callback contained in a container object inside a QVariant and setting it to a property of the sender object then in the receiver slot I get back the property and invoke the callback. I've done some tests today and it's working but the lambda connection would be much better and anyway at this point I want to understand why it's not working.
It could be something related to the combination of Qt version and compiler?
Anyway I'll return to work on next monday so this weekend I can't do much testing.
-
I would suggest you to create a minimal, compilable example and submit a bug report so the developer can take a look on it. There is a similar bug for msvc around: https://bugreports.qt.io/browse/QTBUG-79570
-
@Christian-Ehrlicher
Ok, thanks, on monday I'll proceed as suggested.