Qt dll库信号槽连接失败:QObject::connect: signal not found in Lib

创建库如下

class Lib : public QObject {
Q_OBJECT

signals:
    void testSignal();
}

然后创建App,App中连接库:

class App :public QObject{
Q_OBJECT

public:
    App(Lib *lib){
        connect(lib, &Lib::testSignal, []{});
    }
}

结果运行时返回:

QObject::connect: signal not found in Lib

需要对lib进行怎么样的修改才能正常连接信号?

解决办法:要正确连接动态库里的信号声明时需要正确export和import。

#ifdef LIBRARY
#define LIB_EXPORT Q_DECL_EXPORT
#else
#define LIB_EXPORT Q_DECL_IMPORT
#endif

class LIB_EXPORT Lib : public QObject {
Q_OBJECT

signals:
    void testSignal();
}

测试代码:https://download.csdn.net/download/zzwdkxx/12323878 

相关参考:https://blog.51cto.com/devbean/319479  

你可能感兴趣的:(Qt)