Two or more QObject-based classes having the same name put in different namespaces



  • Hello, all. I am having the aforementioned situation. My project includes two or more QObject-based classes that are situated both in different folders and different namespaces. The problem is that at linker stage I receive the following errors:

    Widget.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Inner::Widget::metaObject(void)const " (?metaObject@Widget@Inner@@UEBAPEBUQMetaObject@@XZ)
    Widget.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Inner::Widget::qt_metacast(char const *)" (?qt_metacast@Widget@Inner@@UEAAPEAXPEBD@Z)
    Widget.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Inner::Widget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Widget@Inner@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    debug\TestQmake.exe : fatal error LNK1120: 3 unresolved externals
    

    These are the build errors output having already configured the project this way:

    CONFIG += object_parallel_to_source no_batch
    

    so that the output intermediate binaries - .obj files, are not put in a single directory no matter the sources are hierarchically spread, but to use the same hierarchical structure for the intermediate binaries as that of the sources. Another option is to replace object_parallel_to_source with object_with_source - https://wiki.qt.io/Undocumented_QMake. Saw, that there is already a forum topic concerning exactly the same problem but it is 2+ years old. There are also other posts on the case - #1, #2.

    The actual problem is that as mentioned by @JKSH in the first aforementioned forum topic:
    Hi,
    Unfortunately the meta-object compiler doesn't handle namespaces.
    This has been discussed before, and some workarounds proposed: http://www.qtcentre.org/threads/6753-moc-with-same-file-names

    Is there now a more flexible solution instead of renaming the classes?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.