I am trying to run a simple piece of code using the documentation provided here https://doc.qt.io/qt-5/qnetworkaccessmanager.html. I am using Qt Creator with MSVC2017 64-bit Kit on Windows 10. My knowledge of C++ and Classes is very basic.
The code gives linker errors I don't know why. I have tried cleaning and re-building again but no success. Any help would be appreciated. Thanks!
I create a new project in Qt Creator with mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void replyFinished(QNetworkReply *reply);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
And then add these lines in mainwindow.cpp and compile.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished,
this, &MainWindow::replyFinished);
manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
}
void MainWindow::replyFinished(QNetworkReply *reply)
{
//
}
I get linker errors at the output when I compile using MSVC2017 64-bit Kit. The issue is same if I use a different Kit (MinGW).
Here's my .pro file :
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Here's the compiler output:
12:52:23: Running steps for project Proj2...
12:52:23: Configuration unchanged, skipping qmake step.
12:52:23: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debug\Proj2.exe #C:\Users\HP\AppData\Local\Temp\Proj2.exe.7376.15.jom
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QNetworkRequest::QNetworkRequest(class QUrl const &)" (__imp_??0QNetworkRequest##QEAA#AEBVQUrl###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QNetworkRequest::~QNetworkRequest(void)" (__imp_??1QNetworkRequest##QEAA#XZ) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QNetworkAccessManager::QNetworkAccessManager(class QObject *)" (__imp_??0QNetworkAccessManager##QEAA#PEAVQObject###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QNetworkAccessManager::~QNetworkAccessManager(void)" (__imp_??1QNetworkAccessManager##UEAA#XZ) referenced in function "public: virtual void * __cdecl QNetworkAccessManager::`scalar deleting destructor'(unsigned int)" (??_GQNetworkAccessManager##UEAAPEAXI#Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QNetworkReply * __cdecl QNetworkAccessManager::get(class QNetworkRequest const &)" (__imp_?get#QNetworkAccessManager##QEAAPEAVQNetworkReply##AEBVQNetworkRequest###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QNetworkAccessManager::finished(class QNetworkReply *)" (__imp_?finished#QNetworkAccessManager##QEAAXPEAVQNetworkReply###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)
mainwindow.obj : error LNK2001: unresolved external symbol "protected: virtual class QNetworkReply * __cdecl QNetworkAccessManager::createRequest(enum QNetworkAccessManager::Operation,class QNetworkRequest const &,class QIODevice *)" (?createRequest#QNetworkAccessManager##MEAAPEAVQNetworkReply##W4Operation#1#AEBVQNetworkRequest##PEAVQIODevice###Z)
mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl QNetworkAccessManager::metaObject(void)const " (?metaObject#QNetworkAccessManager##UEBAPEBUQMetaObject##XZ)
mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl QNetworkAccessManager::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#QNetworkAccessManager##UEAAHW4Call#QMetaObject##HPEAPEAX#Z)
mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl QNetworkAccessManager::qt_metacast(char const *)" (?qt_metacast#QNetworkAccessManager##UEAAPEAXPEBD#Z)
mainwindow.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QNetworkAccessManager::staticMetaObject" (__imp_?staticMetaObject#QNetworkAccessManager##2UQMetaObject##B)
Hint on symbols that are defined and could potentially match:
"__declspec(dllimport) public: static struct QMetaObject const QMainWindow::staticMetaObject" (__imp_?staticMetaObject#QMainWindow##2UQMetaObject##B)
mainwindow.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QNetworkReply::staticMetaObject" (__imp_?staticMetaObject#QNetworkReply##2UQMetaObject##B)
Hint on symbols that are defined and could potentially match:
"__declspec(dllimport) public: static struct QMetaObject const QMainWindow::staticMetaObject" (__imp_?staticMetaObject#QMainWindow##2UQMetaObject##B)
debug\Proj2.exe : fatal error LNK1120: 12 unresolved externals
Your .pro file lacks network module import. Change first line to add network library.
QT += core gui network
You can see this from the documentation, it says there
qmake: QT += network
Related
I tried to override the mouseMoveEvent method by subclassing ChartView and I get a linking error which has something to do with the constructor of ChartView class.
class ChartView : public QChartView
{
Q_OBJECT
public:
ChartView(QChart* chart, QWidget* parent = 0);
protected:
void mouseMoveEvent(QMouseEvent* event) override;
};
ChartView::ChartView(QChart* chart, QWidget* parent)
: QChartView(chart, parent)
{
this->setMouseTracking(true);
}
void ChartView::mouseMoveEvent(QMouseEvent* event)
{
qDebug() << event->pos();
}
The error:
1>mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl ChartView::metaObject(void)const " (?metaObject#ChartView##UEBAPEBUQMetaObject##XZ)
1>mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl ChartView::qt_metacast(char const *)" (?qt_metacast#ChartView##UEAAPEAXPEBD#Z)
1>mainwindow.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl ChartView::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#ChartView##UEAAHW4Call#QMetaObject##HPEAPEAX#Z)
When I remove the constructor of ChartView, the problem is gone, but I dont know why, because I also dont understand the error.
What am I doing wrong and how can I fix this problem?
Before building your application, you need to clean qmake and run it again. Then, you can rebuild the solution. Problem is fixed.
I'm trying to create a project using the QGIS class "QApplication" but it seems to fail due to an error I can´t understand.
I'm using this build version of QGIS made for QT5.7, VS2015, W10 x64 and my main.cpp just containts the following lines:
#define CORE_EXPORT __declspec(dllexport)
#include "QGisTest.h"
#include <QtWidgets/QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGisTest w;
w.show();
return a.exec();
}
And when I try to build it, these errors show up:
1>------ Build started: Project: QGisTest, Configuration: Release x64 ------
1> moc_qgsapplication.cpp
1> Creating library C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.lib and object C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.exp
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QMap<class QString,class QString> QgsApplication::mSystemEnvVars21800" (?mSystemEnvVars21800#QgsApplication##0V?$QMap#VQString##V1###A) referenced in function "public: static class QMap<class QString,class QString> __cdecl QgsApplication::systemEnvVars(void)" (?systemEnvVars#QgsApplication##SA?AV?$QMap#VQString##V1###XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QMap<class QString,class QString> QgsApplication::mSystemEnvVars21800" (?mSystemEnvVars21800#QgsApplication##0V?$QMap#VQString##V1###A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static bool QgsApplication::mRunningFromBuildDir21800" (?mRunningFromBuildDir21800#QgsApplication##0_NA) referenced in function "public: static bool __cdecl QgsApplication::isRunningFromBuildDir(void)" (?isRunningFromBuildDir#QgsApplication##SA_NXZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static bool QgsApplication::mRunningFromBuildDir21800" (?mRunningFromBuildDir21800#QgsApplication##0_NA)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildSourcePath21800" (?mBuildSourcePath21800#QgsApplication##0VQString##A) referenced in function "public: static class QString __cdecl QgsApplication::buildSourcePath(void)" (?buildSourcePath#QgsApplication##SA?AVQString##XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QString QgsApplication::mBuildSourcePath21800" (?mBuildSourcePath21800#QgsApplication##0VQString##A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mCfgIntDir21800" (?mCfgIntDir21800#QgsApplication##0VQString##A) referenced in function "public: static class QString __cdecl QgsApplication::cfgIntDir(void)" (?cfgIntDir#QgsApplication##SA?AVQString##XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QString QgsApplication::mCfgIntDir21800" (?mCfgIntDir21800#QgsApplication##0VQString##A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildOutputPath21800" (?mBuildOutputPath21800#QgsApplication##0VQString##A) referenced in function "public: static class QString __cdecl QgsApplication::buildOutputPath(void)" (?buildOutputPath#QgsApplication##SA?AVQString##XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QString QgsApplication::mBuildOutputPath21800" (?mBuildOutputPath21800#QgsApplication##0VQString##A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QStringList QgsApplication::mGdalSkipList21800" (?mGdalSkipList21800#QgsApplication##0VQStringList##A) referenced in function "public: static class QStringList __cdecl QgsApplication::skippedGdalDrivers(void)" (?skippedGdalDrivers#QgsApplication##SA?AVQStringList##XZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static class QStringList QgsApplication::mGdalSkipList21800" (?mGdalSkipList21800#QgsApplication##0VQStringList##A)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static int QgsApplication::mMaxThreads21800" (?mMaxThreads21800#QgsApplication##0HA) referenced in function "public: static int __cdecl QgsApplication::maxThreads(void)" (?maxThreads#QgsApplication##SAHXZ)
1>main.obj : error LNK2001: unresolved external symbol "private: static int QgsApplication::mMaxThreads21800" (?mMaxThreads21800#QgsApplication##0HA)
1>C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\\QGisTest.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I also added to the project this "moc_qgsapplication.cpp" and wrote the line:
#define CORE_EXPORT __declspec(dllexport)
to avoid other compilation problems and linked to the project the QGIS and QT 5.7 libs.
Any idea how to fix it?
EDIT:
I have changed the two lines of main.cpp as suggested and now contains the following code:
#define CORE_EXPORT __declspec(dllimport)
#include "QGisTest.h"
#include <QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGisTest w;
w.show();
return a.exec();
}
but when I try to build it, these erros still show up:
1>------ Build started: Project: QGisTest, Configuration: Release x64 ------
1> moc_qgsapplication.cpp
1> main.cpp
1> Generating Code...
1> Creating library C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.lib and object C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\QGisTest.exp
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QMap<class QString,class QString> QgsApplication::mSystemEnvVars21800" (?mSystemEnvVars21800#QgsApplication##0V?$QMap#VQString##V1###A) referenced in function "public: static class QMap<class QString,class QString> __cdecl QgsApplication::systemEnvVars(void)" (?systemEnvVars#QgsApplication##SA?AV?$QMap#VQString##V1###XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static bool QgsApplication::mRunningFromBuildDir21800" (?mRunningFromBuildDir21800#QgsApplication##0_NA) referenced in function "public: static bool __cdecl QgsApplication::isRunningFromBuildDir(void)" (?isRunningFromBuildDir#QgsApplication##SA_NXZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildSourcePath21800" (?mBuildSourcePath21800#QgsApplication##0VQString##A) referenced in function "public: static class QString __cdecl QgsApplication::buildSourcePath(void)" (?buildSourcePath#QgsApplication##SA?AVQString##XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mCfgIntDir21800" (?mCfgIntDir21800#QgsApplication##0VQString##A) referenced in function "public: static class QString __cdecl QgsApplication::cfgIntDir(void)" (?cfgIntDir#QgsApplication##SA?AVQString##XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QString QgsApplication::mBuildOutputPath21800" (?mBuildOutputPath21800#QgsApplication##0VQString##A) referenced in function "public: static class QString __cdecl QgsApplication::buildOutputPath(void)" (?buildOutputPath#QgsApplication##SA?AVQString##XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static class QStringList QgsApplication::mGdalSkipList21800" (?mGdalSkipList21800#QgsApplication##0VQStringList##A) referenced in function "public: static class QStringList __cdecl QgsApplication::skippedGdalDrivers(void)" (?skippedGdalDrivers#QgsApplication##SA?AVQStringList##XZ)
1>moc_qgsapplication.obj : error LNK2019: unresolved external symbol "private: static int QgsApplication::mMaxThreads21800" (?mMaxThreads21800#QgsApplication##0HA) referenced in function "public: static int __cdecl QgsApplication::maxThreads(void)" (?maxThreads#QgsApplication##SAHXZ)
1>C:\Users\GRODRIGUEZ\Documents\Visual Studio 2015\Projects\QGisTest\x64\Release\\QGisTest.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm trying to link to a static build of Qwt. to create the static build, I modified qwtconfig.pri to contain
#QWT_CONFIG += QwtDll
and I removed all the #define QWT_DLL references in the code.
However, when I link to the library, I get a bunch of undefined references complaining about QSvgRenderer:
15>qwt.lib(qwt_symbol.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSvgRenderer::QSvgRenderer(class QObject *)" (__imp_??0QSvgRenderer##QEAA#PEAVQObject###Z) referenced in function "public: void __cdecl QwtSymbol::setSvgDocument(class QByteArray const &)" (?setSvgDocument#QwtSymbol##QEAAXAEBVQByteArray###Z)
15>qwt.lib(qwt_symbol.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QSvgRenderer::~QSvgRenderer(void)" (__imp_??1QSvgRenderer##UEAA#XZ) referenced in function "public: virtual void * __cdecl QSvgRenderer::`scalar deleting destructor'(unsigned int)" (??_GQSvgRenderer##UEAAPEAXI#Z)
15>qwt.lib(qwt_symbol.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl QSvgRenderer::isValid(void)const " (__imp_?isValid#QSvgRenderer##QEBA_NXZ) referenced in function "void __cdecl qwtDrawSvgSymbols(class QPainter *,class QPointF const *,int,class QSvgRenderer *,class QwtSymbol const &)" (?qwtDrawSvgSymbols##YAXPEAVQPainter##PEBVQPointF##HPEAVQSvgRenderer##AEBVQwtSymbol###Z)
15>qwt.lib(qwt_symbol.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QRectF __cdecl QSvgRenderer::viewBoxF(void)const " (__imp_?viewBoxF#QSvgRenderer##QEBA?AVQRectF##XZ) referenced in function "public: virtual class QRect __cdecl QwtSymbol::boundingRect(void)const " (?boundingRect#QwtSymbol##UEBA?AVQRect##XZ)
15>qwt.lib(qwt_symbol.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl QSvgRenderer::load(class QByteArray const &)" (__imp_?load#QSvgRenderer##QEAA_NAEBVQByteArray###Z) referenced in function "public: void __cdecl QwtSymbol::setSvgDocument(class QByteArray const &)" (?setSvgDocument#QwtSymbol##QEAAXAEBVQByteArray###Z)
15>qwt.lib(qwt_symbol.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QSvgRenderer::render(class QPainter *,class QRectF const &)" (__imp_?render#QSvgRenderer##QEAAXPEAVQPainter##AEBVQRectF###Z) referenced in function "public: void __cdecl QwtSymbol::drawSymbol(class QPainter *,class QRectF const &)const " (?drawSymbol#QwtSymbol##QEBAXPEAVQPainter##AEBVQRectF###Z)
15>qwt.lib(qwt_symbol.obj) : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl QSvgRenderer::metaObject(void)const " (?metaObject#QSvgRenderer##UEBAPEBUQMetaObject##XZ)
15>qwt.lib(qwt_symbol.obj) : error LNK2001: unresolved external symbol "public: virtual int __cdecl QSvgRenderer::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#QSvgRenderer##UEAAHW4Call#QMetaObject##HPEAPEAX#Z)
15>qwt.lib(qwt_symbol.obj) : error LNK2001: unresolved external symbol "public: virtual void * __cdecl QSvgRenderer::qt_metacast(char const *)" (?qt_metacast#QSvgRenderer##UEAAPEAXPEBD#Z)
15>C:\workspace\fixQwt\executables\linkerGUI\bin\Release\linkerGUI.exe : fatal error LNK1120: 9 unresolved externals
Is there something else in the project configuration I need to do so it can link properly to QSvgRenderer?
Guess your version of Qt is without SVG support - or you forget to add it to your project dependency. If you are not interested in SVG stuff at all you could also disable it in qwtconfig.pri as well:
See: "QWT_CONFIG += QwtSvg"
I got a problem with VS2013 and QT5.3.2.
when I am using Websocket, it says unresolved external symbol with QWebSocket::sendTextMessage and other websocket functions.
I have already #include <QtWebSockets/QWebSocket> and set the QT Project Setting and checked WebKit and Network Module.
This is the full error message I have got:
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
This is the code for 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]
How can I solve this problem?
Just find out that add Qt5WebSocketsd.lib to the project will fix the problem. I dont know why this need to be manually, cuz before when I using other libs QT5 plugin will add them automate
According to the manual:
Header: #include <QWebSocketServer>
qmake: QT += websockets
Since: Qt 5.3
Inherits: QObject
I'm creating a QLabel subclass which adds the DoubleClickEvent to it. I have created the following, but I'm getting some strange linker errors, maybe someone can point out what I've done wrong?
//Header
#ifndef IMAGE_LABEL_H
#define IMAGE_LABEL_H
#include <QLabel>
#include <QMouseEvent>
class image_label : public QLabel
{
Q_OBJECT
public:
image_label(QWidget* parent = 0);
~image_label();
signals:
void doubleClicked();
protected:
void mouseDoubleClickEvent(QMouseEvent * e);
};
#endif
//CPP
#include "image_label.h"
#include <QMouseEvent>
image_label::image_label(QWidget* parent) : QLabel(parent)
{
}
image_label::~image_label()
{
}
void image_label::mouseDoubleClickEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton)
{
emit doubleClicked();
QLabel::mouseDoubleClickEvent(e);
}
}
I get the following linker errors when I compile:
image_label.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall image_label::metaObject(void)const " (?metaObject#image_label##UBEPBUQMetaObject##XZ)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall image_label::qt_metacast(char const *)" (?qt_metacast#image_label##UAEPAXPBD#Z)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall image_label::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#image_label##UAEHW4Call#QMetaObject##HPAPAX#Z)
image_label.obj : error LNK2019: unresolved external symbol "protected: void __thiscall image_label::doubleClicked(void)" (?doubleClicked#image_label##IAEXXZ) referenced in function "protected: virtual void __thiscall image_label::mouseDoubleClickEvent(class QMouseEvent *)" (?mouseDoubleClickEvent#image_label##MAEXPAVQMouseEvent###Z)
Can anybody help why I get these errors?
You must run the MOC preprocessor on the file image_label.h. This generates a file moc_image_label.cppthat you must include in the build. The error message indicates that you have not done this. (The symbols image_label::metaObject etc. that are mentioned in the error message are defined in moc_image_label.cpp.)