VS2013与QT5.3.2使用Websocket并得到一个未解决的外部符号问题

时间:2015-02-15 10:43:40

标签: c++ qt

我遇到了VS2013和QT5.3.2的问题。 当我使用Websocket时,它用QWebSocket :: sendTextMessage和其他websocket函数表示未解析的外部符号。

我已经#include <QtWebSockets/QWebSocket>并设置了QT项目设置并检查了WebKit和网络模块。

这是我收到的完整错误消息:

1&gt; mainwindow.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:virtual __thiscall QWebSocket :: ~QWebSocket(void)”(__ imp _ ?? 1QWebSocket @@ UAE @ XZ),在函数“public”中引用:virtual __thiscall MWebSocket :: ~MWebSocket(void)“(?? 1MWebSocket @@ UAE @ XZ) 1&gt; MWebSocket.obj:错误LNK2001:未解析的外部符号“__declspec(dllimport)public:virtual __thiscall QWebSocket :: ~QWebSocket(void)”(__ imp _ ?? 1QWebSocket @@ UAE @ XZ) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:__ thishisall QWebSocket :: QWebSocket(class QString const&amp;,enum QWebSocketProtocol :: Version,class QObject *)”(__ imp _ ?? 0QWebSocket @@ QAE @ ABVQString @@ W4Version @ QWebSocketProtocol @@ PAVQObject @@@ Z),在函数“public:__thiscall MWebSocket :: MWebSocket(class QUrl const&amp;,class QObject *)”中引用(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@ Z) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:__ int64 __thiscall QWebSocket :: sendTextMessage(class QString const&amp;)”(__ imp_?sendTextMessage @ QWebSocket @@ QAE_JABVQString @@@ Z),引用于function“private:void __thiscall MWebSocket :: onConnected(void)”(?onConnected @ MWebSocket @@ AAEXXZ) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket :: close(enum QWebSocketProtocol :: CloseCode,class QString const&amp;)”(__ imp_?close @ QWebSocket @@ QAEXW4CloseCode @ QWebSocketProtocol @@ ABVQString @@@ Z),在函数“private:void __thiscall MWebSocket :: onTextMessageReceived(class QString)”中引用(?onTextMessageReceived @ MWebSocket @@ AAEXVQString @@@ Z) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket :: open(class QUrl const&amp;)”(__ imp_?open @ QWebSocket @@ QAEXABVQUrl @@@ Z),引用于function“public:__thiscall MWebSocket :: MWebSocket(class QUrl const&amp; amp; QObject *)”(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@ Z) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket :: connected(void)”(__ imp_?connected @ QWebSocket @@ QAEXXZ),在函数“public:__thiscall MWebSocket ::”中引用MWebSocket(类QUrl const&amp;,类QObject *)“(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@ Z) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket :: disconnected(void)”(__ imp_?disconnected @ QWebSocket @@ QAEXXZ),在函数“public:__thiscall MWebSocket ::”中引用MWebSocket(类QUrl const&amp;,类QObject *)“(?? 0MWebSocket @@ QAE @ ABVQUrl @@ PAVQObject @@@ Z) 1&gt; MWebSocket.obj:错误LNK2019:未解析的外部符号“__declspec(dllimport)public:void __thiscall QWebSocket :: textMessageReceived(class QString const&amp;)”(__ imp_?textMessageReceived @ QWebSocket @@ QAEXABVQString @@@ Z),引用于function“private:void __thiscall MWebSocket :: onConnected(void)”(?onConnected @ MWebSocket @@ AAEXXZ) 1&gt; MWebSocket.obj:错误LNK2001:未解析的外部符号“__declspec(dllimport)public:static struct QMetaObject const QWebSocket :: staticMetaObject”(__ imp_?staticMetaObject @ QWebSocket @@ 2UQMetaObject @@ B) 1&gt; 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]

任何人都知道如何解决这个问题?感谢

2 个答案:

答案 0 :(得分:3)

只是发现将Qt5WebSocketsd.lib添加到项目中将解决问题。我不知道为什么这需要手动,因为之前我使用其他库时QT5插件会自动添加它们

答案 1 :(得分:1)

阅读f。手册

Header: #include <QWebSocketServer>
qmake:  QT += websockets
Since:  Qt 5.3
Inherits:   QObject