title: Qt C++ LNK2019: unresolved external symbol using QNetworkAccessManager
body: <p>I am trying to run a simple piece of code using the documentation provided here <a href="https://doc.qt.io/qt-5/qnetworkaccessmanager.html" rel="nofollow noreferrer">https://doc.qt.io/qt-5/qnetworkaccessmanager.html</a>. I am using Qt Creator with MSVC2017 64-bit Kit on Windows 10. My knowledge of C++ and Classes is very basic.</p>
  
  <p>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!</p>
  
  <p>I create a new project in Qt Creator with mainwindow.h</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QtNetwork/QNetworkAccessManager&gt;
  #include &lt;QtNetwork/QNetworkReply&gt;
  
  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
  </code></pre>
  
  <p>And then add these lines in mainwindow.cpp and compile.</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      QNetworkAccessManager *manager = new QNetworkAccessManager(this);
      connect(manager, &amp;QNetworkAccessManager::finished,
              this, &amp;MainWindow::replyFinished);
  
      manager-&gt;get(QNetworkRequest(QUrl("http://qt-project.org")));
  }
  
  void MainWindow::replyFinished(QNetworkReply *reply)
  {
      //
  }
  </code></pre>
  
  <p>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).</p>
  
  <p>Here's my .pro file :</p>
  
  <pre><code>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
  
  
  </code></pre>
  
  <p>Here's the compiler output:</p>
  
  <pre><code>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 &amp;)" (__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 &amp;)" (__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 &amp;,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
  
  </code></pre>