Im working on a project using Qt/C++ originally compiled with MinGW64 (gcc 4.8). I decided to "port" it to MSVC2013, since I need to use some Windows API functions that doesn't work well in MinGW, but right now I'm stuck at this error:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl IMLoginView::clearFieldPass(void)" (?clearFieldPass#IMLoginView##QEAAXXZ) referenced in function "public: void __cdecl MainWindow::showConnectionErrorDialog(void)" (?showConnectionErrorDialog#MainWindow##QEAAXXZ)
imingestinglist.obj:-1: error: LNK2019: unresolved external symbol "public: static class QString __cdecl IMStorageSystem::getLogDir(void)" (?getLogDir#IMStorageSystem##SA?AVQString##XZ) referenced in function "private: class QList<int> __cdecl IMIngestingList::loadList(void)" (?loadList#IMIngestingList##AEAA?AV?$QList#H##XZ)
moc_imloginview.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl IMLoginView::login(void)" (?login#IMLoginView##QEAAXXZ) referenced in function "private: static void __cdecl IMLoginView::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall#IMLoginView##CAXPEAVQObject##W4Call#QMetaObject##HPEAPEAX#Z)
moc_imloginview.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl IMLoginView::handleError(enum ALFRED_ACCESS_ERROR)" (?handleError#IMLoginView##QEAAXW4ALFRED_ACCESS_ERROR###Z) referenced in function "private: static void __cdecl IMLoginView::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall#IMLoginView##CAXPEAVQObject##W4Call#QMetaObject##HPEAPEAX#Z)
moc_imloginview.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl IMLoginView::userDisconnected(void)" (?userDisconnected#IMLoginView##QEAAXXZ) referenced in function "private: static void __cdecl IMLoginView::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)"
The problem is: These methods aren't part of some external library, but part of the project itself. And I already triple checked that they are implemented. They aren't part of any template class either, but normal classes, and the log says the cpp files are being compiled. The same project links just fine with MinGW64.
I'm currently using Qt Creator 3.3.2 and QT 5.3.2.
What can be happening?
EDIT:
I Can't show much code, since its a closed-source project, but I can at least show the header and implementation layout of the methods:
imloginview.h:
class IMLoginView : public QWidget
{
Q_OBJECT
public:
explicit IMLoginView(QWidget *parent = 0);
void clearFieldPass();
~IMLoginView();
private:
//Lots of attributes
void configureComponents();
void keyPressEvent(QKeyEvent *event);
signals:
public slots:
void login();
void handleError(ALFRED_ACCESS_ERROR error);
void userDisconnected();
}
imloginview.cpp:
IMLoginView::IMLoginView(QWidget *parent) : //lots of initializations here
{
//Implementation
}
IMLoginView::~IMLoginView()
{
}
void IMLoginView::clearFieldPass()
{
//implementation
}
void IMLoginView::configureComponents()
{
//Implementation
}
void IMLoginView::keyPressEvent(QKeyEvent *event)
{
//implementation
}
void IMLoginView::login()
{
//implementation
}
void IMLoginView::handleError(ALFRED_ACCESS_ERROR error)
{
//implementation
}
void IMLoginView::userDisconnected()
{
//implementation
}
I'm sorry I really can't provide the actual method code, but its closed-source. =/
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 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 new to C++ and have encountered a problem while running my app. I googled the problem but since most results were with linking libraries I started a new thread.
I have a class CResizableDialog which I'm inheriting from my VtkDialogTest2 dialog class.
VtkDialogTest2.h;
#pragma once
#include "CResizableDialog.h"
#ifdef _WIN32_WCE
#error "CDHtmlDialog is not supported for Windows CE."
#endif
// VtkDialogTest2 dialog
class VtkDialogTest2 : public CResizableDialog
{
DECLARE_DYNCREATE(VtkDialogTest2)
public:
VtkDialogTest2(CWnd* pParent = NULL); // standard constructor
virtual ~VtkDialogTest2();
// Overrides
HRESULT OnButtonOK(IHTMLElement *pElement);
HRESULT OnButtonCancel(IHTMLElement *pElement);
// Dialog Data
enum { IDD = IDD_DIALOG4 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
};
VtkDialogTest2.cpp
#include "stdafx.h"
#include "Geometry.h"
#include "VtkDialogTest2.h"
IMPLEMENT_DYNCREATE(VtkDialogTest2, CResizableDialog)
VtkDialogTest2::VtkDialogTest2(CWnd* pParent /*=NULL*/)
: CResizableDialog(VtkDialogTest2::IDD, pParent),
{
}
VtkDialogTest2::~VtkDialogTest2()
{
}
void VtkDialogTest2::DoDataExchange(CDataExchange* pDX)
{
CResizableDialog::DoDataExchange(pDX);
}
BOOL VtkDialogTest2::OnInitDialog()
{
CResizableDialog::OnInitDialog();
//some code
return TRUE; // return TRUE unless you set the focus to a control
}
BEGIN_MESSAGE_MAP(VtkDialogTest2, CResizableDialog)
ON_BN_CLICKED(IDOK, &VtkDialogTest2::OnBnClickedOk)
END_MESSAGE_MAP()
//some code
I can't figure out what I'm doing wrong. I downloaded an example from the web which uses the CResizableDialog.h class the exact same way and copied both CResizableDialog.h and CResizableDialog.cpp into my project.
The errors I'm getting are;
1>VtkDialogTest2.obj : error LNK2019: unresolved external symbol "public: __thiscall CResizableDialog::CResizableDialog(unsigned int,class CWnd *)" (??0CResizableDialog##QAE#IPAVCWnd###Z) referenced in function "public: __thiscall VtkDialogTest2::VtkDialogTest2(class CWnd *)" (??0VtkDialogTest2##QAE#PAVCWnd###Z)
1>VtkDialogTest2.obj : error LNK2019: unresolved external symbol "protected: virtual int __thiscall CResizableDialog::OnInitDialog(void)" (?OnInitDialog#CResizableDialog##MAEHXZ) referenced in function "protected: virtual int __thiscall VtkDialogTest2::OnInitDialog(void)" (?OnInitDialog#VtkDialogTest2##MAEHXZ)
1>VtkDialogTest2.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const * __stdcall CResizableDialog::GetThisMessageMap(void)" (?GetThisMessageMap#CResizableDialog##KGPBUAFX_MSGMAP##XZ)
1>C:\Users\Geometry.exe : fatal error LNK1120: 3 unresolved externals
Any input will be highly appreciated.
The error was because I copied the CResizableDialog.h and CResizableDialog.cpp files directly into the project folder. I later noticed that they didn't show up in the solution window and copied them to the window as well. After that the errors disappeared.
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.)