Getting "QObject::connect: signal not found" when using a signals of different libraries.
-
wrote on 16 Nov 2022, 23:30 last edited by rkhaotix
Hey guys! I hope you all doing fine!
I'm here to ask for help from the Qt specialists... :D
I'm struggling to make my codebase work on Windows after refactoring the classic signal/slot connection
connect(sender, SIGNAL(signal), receiver, SLOT(slot))
to the not-so-new one based on the pointer to function/methodconnect(sender, &SenderClass::signal, receiver, &ReceiverClass::slot)
.The code builds and works fine on Linux and macOS. But on Windows, building with MingW64 (gcc 12) and Qt 6.3.1 I get a lot of runtime errors during the application startup: qt.core.qobject.connect: QObject::connect: signal not found in BaseGraphicObject. If I keep using the software I receive similar runtime errors but now related to other classes in my project. I've managed to track where the majority of these errors occur but I have no idea how to solve them.
First, let me give some background on how my project is built. pgModeler is divided into six library subprojects and other four app subprojects. Each executable is linked against one or more libraries. Libraries share between them their classes, namespaces, and other things. In some libraries, I do signal/slot connections by referencing classes defined in other libraries, and I think this is one of the problems.
Being said that, the simple constructor below raises the runtime error:
TableView::TableView(PhysicalTable *table) : BaseTableView(table) { connect(table, &PhysicalTable::s_objectModified, this, &TableView::configureObject); this->configureObject(); }
The class
TableView
is defined in the library calledlibcanvas
. The classPhysicalTable```` is derived from
BaseTable, which in turn, is derived from ```BaseGraphicObject
. Those three classes are defined in the library calledlibcore
. The signals_objectModified
which is referenced by&PhysicalTable::s_objectModified
inconnect()
is defined in the base classBaseGraphicObject
as you can see:class BaseGraphicObject: public QObject, public BaseObject { private: Q_OBJECT ... signals: //! \brief Signal emitted when the user calls the setModified() method void s_objectModified(); //! \brief Signal emitted when the user calls the setProtected() method void s_objectProtected(bool); ... };
After some research, I found that the problem could be the fact that I was not exporting the symbols in the generated DLLs. Strangely I never needed to use this mechanism when using the old signal/slot syntax since the software was working flawlessly on the three platforms. Anyway, I tried to follow the docs about creating and exporting/importing symbols but without success. The code builds fine but I still get the runtime errors.
Now, I'm out of ideas on how to solve this problem, my software is broken on Windows, and I just wouldn't like to revert the signal/slot connecting syntax because I like the readiness and compile-time checking that the new one provides. :(
Is there anything else that I can do? I appreciate any help!
Thanks in advance. -
wrote on 17 Nov 2022, 01:02 last edited by ChrisW67
If the code is compiling then any new-style connects must be essentially correct because, as you note, the error checking happens at compile time.
Run time messages of the type you are seeing are more typical of old-style connections. I am assuming there are absolutely no old-style connect() calls present in the modified project, including libraries.
Have you adorned every public class in the libraries with a MYSHAREDLIB_EXPORT type macro? In this case BaseGraphicObject, BaseTable and TableView.
Has qmake been run and everything been built from a completely clean state?
BTW: Thank you for a well constructed query.
-
wrote on 17 Nov 2022, 02:08 last edited by rkhaotix
Hi @ChrisW67 ,
Thanks for your response. After reading twice the sentence "Have you adorned every public class in the libraries with a MYSHAREDLIB_EXPORT type macro?" I finally found what I was doing wrong!
I created the macro you mentioned but used the same macro in all classes in all six libraries, which of course is incorrect! So, I created six macros and marked the classes accordingly and now everything is working again!
Thank you very much! :D
-
wrote on 17 Nov 2022, 02:18 last edited by
I love it when a plan comes together.
1/4