VS2013与QT5.3.2使用Websocket,并得到一个未解决的外部符号问题
VS2013 with QT5.3.2 using Websocket and got a unresolved external symbol issue
我遇到了VS2013和QT5.3.2的问题。当我使用Websocket时,它会用QWebSocket::sendTextMessage和其他Websocket函数显示未解析的外部符号。
我已经#include <QtWebSockets/QWebSocket>
并设置了QT项目设置,并检查了WebKit和网络模块。
这是我收到的完整错误信息:
1>mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QWebSocket::~QWebSocket(void)" (__imp_??1QWebSocket@@UAE@XZ),referenced in function "public: virtual __thiscall MWebSocket::~MWebSocket(void)" (??1MWebSocket@@UAE@XZ)
1>MWebSocket.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QWebSocket::~QWebSocket(void)" (__imp_??1QWebSocket@@UAE@XZ)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QWebSocket::QWebSocket(class QString const &,enum QWebSocketProtocol::Version,class QObject *)" (__imp_??0QWebSocket@@QAE@ABVQString@@W4Version@QWebSocketProtocol@@PAVQObject@@@Z),referenced in function "public: __thiscall MWebSocket::MWebSocket(class QUrl const &,class QObject *)" (??0MWebSocket@@QAE@ABVQUrl@@PAVQObject@@@Z)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall QWebSocket::sendTextMessage(class QString const &)" (__imp_?sendTextMessage@QWebSocket@@QAE_JABVQString@@@Z),referenced in function "private: void __thiscall MWebSocket::onConnected(void)" (?onConnected@MWebSocket@@AAEXXZ)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWebSocket::close(enum QWebSocketProtocol::CloseCode,class QString const &)" (__imp_?close@QWebSocket@@QAEXW4CloseCode@QWebSocketProtocol@@ABVQString@@@Z),referenced in function "private: void __thiscall MWebSocket::onTextMessageReceived(class QString)" (?onTextMessageReceived@MWebSocket@@AAEXVQString@@@Z)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWebSocket::open(class QUrl const &)" (__imp_?open@QWebSocket@@QAEXABVQUrl@@@Z),referenced in function "public: __thiscall MWebSocket::MWebSocket(class QUrl const &,class QObject *)" (??0MWebSocket@@QAE@ABVQUrl@@PAVQObject@@@Z)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWebSocket::connected(void)" (__imp_?connected@QWebSocket@@QAEXXZ),referenced in function "public: __thiscall MWebSocket::MWebSocket(class QUrl const &,class QObject *)" (??0MWebSocket@@QAE@ABVQUrl@@PAVQObject@@@Z)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWebSocket::disconnected(void)" (__imp_?disconnected@QWebSocket@@QAEXXZ),referenced in function "public: __thiscall MWebSocket::MWebSocket(class QUrl const &,class QObject *)" (??0MWebSocket@@QAE@ABVQUrl@@PAVQObject@@@Z)
1>MWebSocket.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWebSocket::textMessageReceived(class QString const &)" (__imp_?textMessageReceived@QWebSocket@@QAEXABVQString@@@Z),referenced in function "private: void __thiscall MWebSocket::onConnected(void)" (?onConnected@MWebSocket@@AAEXXZ)
1>MWebSocket.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QWebSocket::staticMetaObject" (__imp_?staticMetaObject@QWebSocket@@2UQMetaObject@@B)
1>debug/MapleUI.exe : fatal error LNK1120: 9 unresolved externals
这是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添加到项目中就能解决问题。我不知道为什么这需要手动,因为之前当我使用其他libs QT5插件时,会添加它们来自动
根据手册:
Header: #include <QWebSocketServer>
qmake: QT += websockets
Since: Qt 5.3
Inherits: QObject
相关文章:
- 节俭并发:未解决的外部问题
- 未解决的外部链接问题
- Visual Studio 2017 中的 QtMetaObject 未解决的外部错误
- 'auto *x = new some_struct{};"是一个未初始化的变量?
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 解释未解决的外部C++
- 在VSCode中编译C++给了我一个未定义的参考
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 我对C++程序有一个未定义的参考,不知道如何处理它
- 函数路径追加上未解决的外部符号错误
- 我正在为学校开发一个小班模板实验室,我的代码无法编译,它给了我一个未解析的外部符号
- 是否有可能通过指向另一个未关联的子对象的指针来获取指向一个子对象的指针?
- 为什么这是一个未定义的行为?
- DLIB On visual studio 2015抛出一个未解决的外部错误
- 未解决的外部符号,带有静态lib,它使用了另一个静态lib
- 另一个与未解决符号相关的问题
- VS2013与QT5.3.2使用Websocket,并得到一个未解决的外部符号问题
- 我有一个错误LNK2019:未解决的外部符号错误(要查看少量代码)
- QT和未解决的下一个符号
- 无法将一个项目的头和 CPP 文件与另一个项目链接 LNK2019:未解决的外部符号错误