外部DLL中缺少QT信号

Qt signals missing in external dll

本文关键字:QT 信号 DLL 外部      更新时间:2023-10-16

我在应用程序中使用的iris XMPP库中有信号。在Mac OS X和Linux上一切正常,但是Windows会产生一堆未找到警告的信号。

warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::QCATLSHandler
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::Client
warning: QObject::connect: signal not found in XMPP::Client
warning: QObject::connect: signal not found in XMPP::Client
warning: QObject::connect: signal not found in XMPP::Client

我试图使用的一个信号的示例是

signals:
    void srvLookup(const QString &server);

我的连接电话

conn = std::make_shared<XMPP::AdvancedConnector>();
QObject::connect(conn.get(), &XMPP::AdvancedConnector::srvLookup, this, &XmppConnection::connServerLookupHandler);
QObject::connect(conn.get(), &XMPP::AdvancedConnector::srvResult, this, &XmppConnection::connServerResultHandler);
QObject::connect(conn.get(), &XMPP::AdvancedConnector::httpSyncStarted, this, &XmppConnection::connHttpSyncStartedHandler);
QObject::connect(conn.get(), &XMPP::AdvancedConnector::httpSyncFinished, this, &XmppConnection::connHttpSyncFinishedHandler);
if(QCA::isSupported("tls")) {
    tls = make_unique<QCA::TLS>();
    tlsHandler = make_unique<XMPP::QCATLSHandler>(tls.get());
    // dont check the certificate because we self sign
    tlsHandler->setXMPPCertCheck(false);
    QObject::connect(tlsHandler.get(), &XMPP::QCATLSHandler::tlsHandshaken, this, &XmppConnection::tlsHandshakenHandler);
} else {
    tls = 0;
    tlsHandler = 0;
}
stream = std::make_shared<XMPP::ClientStream>(conn.get(), tlsHandler.get());
QObject::connect(stream.get(), &XMPP::ClientStream::connected, this, &XmppConnection::streamConnectedHandler);
QObject::connect(stream.get(), &XMPP::ClientStream::securityLayerActivated, this, &XmppConnection::streamSecurityLayerActivatedHanlder);
QObject::connect(stream.get(), &XMPP::ClientStream::needAuthParams, this, &XmppConnection::streamNeedAuthParamsHandler);
QObject::connect(stream.get(), &XMPP::ClientStream::authenticated, this, &XmppConnection::streamAuthenticatedHandler);
QObject::connect(stream.get(), &XMPP::ClientStream::connectionClosed, this, &XmppConnection::streamConnectionClosedHandler);
QObject::connect(stream.get(), &XMPP::ClientStream::delayedCloseFinished, this, &XmppConnection::streamDelayedCloseFinished);
QObject::connect(stream.get(), &XMPP::ClientStream::readyRead, this, &XmppConnection::streamReadyRead);
QObject::connect(stream.get(), &XMPP::ClientStream::stanzaWritten, this, &XmppConnection::streamStanzaWritten);
QObject::connect(stream.get(), &XMPP::ClientStream::warning, this, &XmppConnection::streamWarningHandler);
QObject::connect(stream.get(), &XMPP::ClientStream::error, this, &XmppConnection::streamErrorHandler);
xmpp = std::make_shared<XMPP::Client>();
QObject::connect(xmpp.get(), &XMPP::Client::rosterRequestFinished, this, &XmppConnection::onRosterRequestFinished);
QObject::connect(xmpp.get(), &XMPP::Client::rosterItemAdded, this, &XmppConnection::onRosterItemAdded);
QObject::connect(xmpp.get(), &XMPP::Client::rosterItemUpdated, this, &XmppConnection::onRosterItemUpdated);
QObject::connect(xmpp.get(), &XMPP::Client::rosterItemRemoved, this, &XmppConnection::onRosterItemRemoved);

这是我的实际插槽之一

void XmppConnection::connServerLookupHandler(const QString &server)
{
    qDebug() << "Looking up Server: " << server;
    return;
}

我无法弄清楚为什么Mac和Linux工作和Windows不知道。我已经考虑过编译器选项,但是我使用CMAKE,因此除非我的Linux GCC和MingW GCC之间存在巨大差异,否则我不知道为什么这会很重要。我正在使用Conne Call CALL显示的C 11功能。但是我适当地编译和链接,因此我假设C 11功能正如我预期的那样工作。有人有一个主意吗?

编辑:

我正在使用QT5.2.0 Mingw OpenGL。我正在使用QT5.2.0随附的mingw,即Mingw48 32.我正在与我的应用程序同时编译库,Iris,并使用CMake到Automoc,将其设置为链接依赖性,并包括正确的链接依赖标题。

edit2:包括我所有的连接电话。

事实证明,我缺乏窗户开发的事物,发现我在屁股上咬了我。因此,对于Windows,您需要在Windows上导出符号。

所以我添加了

/**
 * @brief Allows for windows exported symbols
 *
 * Windows requries a special modifier to allow them to export correctly.
 * This macro allows that while leaving Mac OS X and Linux alone.
 *
 * While Qt can tell us if it was make for WIN32, MAC, or LINUX, It cannot
 * tell us if we are being statically or dynamically linked. That is why
 * this is using the CMake variables instead of Qt
 */
#if defined (_WIN32)
  // cmake makes this variable if your a shared library (projectname_EXPORTS)
  #if defined(iris_EXPORTS)
    #define IRIS_EXPORT Q_DECL_EXPORT
  #else
    #define IRIS_EXPORT Q_DECL_IMPORT
  #endif /* iris_EXPORTS */
#else /* defined (_WIN32) */
 #define IRIS_EXPORT
#endif

然后我会在每个

上使用它
class IRIS_EXPORT ClassNameHere { ... }
IRIS_EXPORT void StaticFunctionNameHere(){...}

这解决了我的问题。

有关此信息的更多信息,请访问此处,这里或这里。