'unresolved external symbol "public: static struct QMetaObject const" when linking to a shared Q_OBJECT

I want to make two QObject libraries using cmake on windows: ProA & ProB, where ProB depend on ProA.

The code of ProA looks like:

class ProA_Export ProA: public QWidget
{
    Q_OBJECT
public:
    ...
};

The ProB links ProA in CMake: target_link_libraries(ProB ProA).

Then, when I #include "ProA.h" in ProB, it reproted:

unresolved external symbol "public: static struct QMetaObject const ProA::staticMetaObject"

If I remove the Q_OBJECT from ProA, everything is OK except that the signal-slot of QT do not work.

So, how can I solve the unresolved external symbol problem caused by Q_OBJECT?

Any suggestion is appreciated~~~

--------------------- update --------------------

Finally, I find that it is connect cause the problem.

I change

connect(m_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChangeSlot(int)));

to

connect(m_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &ProA::indexChangeSlot)

Then, everything is OK. In addition, I find Q_OBJECT is not necessary.

Hope it can help somebody.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source