我遇到了VS2013和QT5.3.2的问题。
当我使用Websocket时,它使用QWebSocket::sendTextMessage和其他websocket函数显示未解析的外部符号。
我已经#include <QtWebSockets/QWebSocket>
并设置了QT项目设置,并检查了WebKit和网络模块。
这是我得到的完整错误消息:
1> mainwindow.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:虚拟__thiscall QWebSocket::〜QWebSocket(void)”(__ imp _ ?? 1QWebSocket @@ UAE @ XZ),在函数“public:virtual __thiscall中引用” MWebSocket::〜MWebSocket(void)“(?? 1MWebSocket @@ UAE @ XZ)
1> MWebSocket.obj:错误LNK2001:未解析的外部符号“__declspec(dllimport)公共(public):虚拟__thiscall QWebSocket::〜QWebSocket(void)”(__ imp _ ?? 1QWebSocket @@ UAE @ XZ)
1> MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)公共(public):__thiscall QWebSocket::QWebSocket(class QString const&,enum QWebSocketProtocol::Version,class QObject *)”(__imp _ ?? 0QWebSocket @@ QAE @ ABVQString @@ W4Version @ QWebSocketProtocol @@ PAVQObject @@@ Z),在函数“public:__thiscall MWebSocket::MWebSocket(class QUrl const&,class QObject *)”中引用(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @ @@ Z)
1> MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)公共(public):__int64 __thiscall QWebSocket::sendTextMessage(class QString const&)”(__imp_?sendTextMessage @ QWebSocket @@ QAE_JABVQString @@@ Z),在函数中引用“私有(private):无效__thiscall MWebSocket::onConnected(void)”(?onConnected @ MWebSocket @@ AAEXXZ)
1> MWebSocket.obj:错误LNK2019:未解决的外部符号“__declspec(dllimport)公共(public):void __thiscall QWebSocket::close(枚举QWebSocketProtocol::CloseCode,类QString const&)”(__imp_?close @ QWebSocket @@ QAEXW4CloseCode @ QWebSocketProtocol @ @ABVQString @@@@ Z),在函数“私有(private):void __thiscall MWebSocket::onTextMessageReceived(class QString)”中引用(?onTextMessageReceived @ MWebSocket @@ AAEXVQString @@@ Z)
1> MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket::open(class QUrl const&)”(__imp_?open @ QWebSocket @@ QAEXABVQUrl @@@@ Z,在函数中引用“public:__thiscall MWebSocket::MWebSocket(class QUrl const&,class QObject *)”(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@@ Z)
1> MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket::connected(void)”(__ imp_?connected @ QWebSocket @@ QAEXXZ),在函数“public:__thiscall MWebSocket::”中引用MWebSocket(class QUrl const&,class QObject *)“(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@ Z)
1> MWebSocket.obj:错误LNK2019:未解决的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket::disconnected(void)”(__ imp_?disconnected @ QWebSocket @@ QAEXXZ),在函数“public:__thiscall MWebSocket::中引用” MWebSocket(class QUrl const&,class QObject *)“(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@ Z)
1> MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)公共(public):void __thiscall QWebSocket::textMessageReceived(class QString const&)”(__imp_?textMessageReceived @ QWebSocket @@ QAEXABVQString @@@@ Z),在函数中引用“私有(private):无效__thiscall MWebSocket::onConnected(void)”(?onConnected @ MWebSocket @@ AAEXXZ)
1> MWebSocket.obj:错误LNK2001:未解析的外部符号“__declspec(dllimport)公共(public):静态结构QMetaObject const QWebSocket::staticMetaObject”(__ imp_?staticMetaObject @ QWebSocket @@ 2UQMetaObject @@ B)
1> debug / \ MapleUI.exe:致命错误LNK1120:9个未解决的外部组件
这是Websocket的代码:
//HEADER
#pragma once
#include "global.h"
class MWebSocket : public QObject
{
Q_OBJECT
public:
explicit MWebSocket(const QUrl &url, QObject *parent = Q_NULLPTR);
Q_SIGNALS:
void closed();
private Q_SLOTS:
void onConnected();
void onTextMessageReceived(QString message);
private:
QWebSocket m_webSocket;
QUrl m_url;
};
//CPP
#include "global.h"
#include "MWebSocket.h"
QT_USE_NAMESPACE
//! [constructor]
MWebSocket::MWebSocket(const QUrl &url, QObject *parent) :
QObject(parent),
m_url(url)
{
connect(&m_webSocket, &QWebSocket::connected, this, &MWebSocket::onConnected);
connect(&m_webSocket, &QWebSocket::disconnected, this, &MWebSocket::closed);
m_webSocket.open(QUrl(url));
}
//! [constructor]
//! [onConnected]
void MWebSocket::onConnected()
{
qDebug() << "WebSocket connected";
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &MWebSocket::onTextMessageReceived);
m_webSocket.sendTextMessage(QStringLiteral("H2ello, world!"));
}
//! [onConnected]
//! [onTextMessageReceived]
void MWebSocket::onTextMessageReceived(QString message)
{
qDebug() << "Message received:" << message;
m_webSocket.close();
}
//! [onTextMessageReceived]
有谁知道如何解决这个问题?谢谢
最佳答案
只需发现将Qt5WebSocketsd.lib添加到项目即可解决此问题。我不知道为什么这需要手动操作,因为在我使用其他库QT5插件之前,它们会自动添加
关于c++ - 使用Websocket的QT5.3.2的VS2013并出现 Unresolved external symbol 问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28525250/