Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: LNK2019: unresolved external symbol
Qt 6.11 is out! See what's new in the release blog

error: LNK2019: unresolved external symbol

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 5.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zzzhhhzzzhhh
    wrote on last edited by
    #1

    I am brand new to Qt so I am learning it by following a video called "Learning Qt 5". But I soon encountered a problem. The project is as follows.

    ============ main.cpp ===============

    #include <QCoreApplication>
    #include <QtDebug>
    #include "myparentclass.h"
    #include "mychild.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        MyParentClass * parent= new MyParentClass();
        MyChild * child=new MyChild(parent);
    
        qDebug()<<"Hello World!\n";
    
        delete parent;
        delete child;
    
        return a.exec();
    }
    

    ================= myparentclass.h ===================

    #ifndef MYPARENTCLASS_H
    #define MYPARENTCLASS_H
    
    #include <QObject>
    
    class MyParentClass : public QObject
    {
        Q_OBJECT
    public:
        explicit MyParentClass(QObject *parent = 0);
        ~MyParentClass();
    
    signals:
    
    public slots:
    };
    
    #endif // MYPARENTCLASS_H
    

    ================= myparentclass.cpp ====================

    #include "myparentclass.h"
    #include <QCoreApplication>
    
    MyParentClass::MyParentClass(QObject *parent) : QObject(parent)
    {
    
    }
    
    MyParentClass::~MyParentClass()
    {
        qDebug("MyParentClass destructor");
        QCoreApplication::quit();
    }
    

    ================== mychild.h ========================

    #ifndef MYCHILD_H
    #define MYCHILD_H
    
    #include <QObject>
    
    class MyChild : public QObject
    {
        Q_OBJECT
    public:
        explicit MyChild(QObject *parent = 0);
        ~MyChild();
    
    signals:
    
    public slots:
    };
    
    #endif // MYCHILD_H
    

    ==================== mychild.cpp =====================

    #include "mychild.h"
    
    MyChild::MyChild(QObject *parent) : QObject(parent)
    {
    }
    
    MyChild::~MyChild()
    {
        qDebug("MyChild destructor");
        this->parent()->deleteLater();
    }
    

    I have added all these files into the Qt project:
    alt text

    But when I build it, I got errors:
    alt text

    I searched some previous threads which suggest clean and rebuild, but it does not work.

    The Qt I am using is 5.10.0 and the Qt Creator is 4.5.0. The OS is Windows 7. I have Visual Studio 2015 installed so I want to use VS to compile. This is the kit configuration:
    alt text

    So, what am I missing? How to fix the errors? Thank you.

    mrjjM 1 Reply Last reply
    0
    • Z zzzhhhzzzhhh

      I am brand new to Qt so I am learning it by following a video called "Learning Qt 5". But I soon encountered a problem. The project is as follows.

      ============ main.cpp ===============

      #include <QCoreApplication>
      #include <QtDebug>
      #include "myparentclass.h"
      #include "mychild.h"
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          MyParentClass * parent= new MyParentClass();
          MyChild * child=new MyChild(parent);
      
          qDebug()<<"Hello World!\n";
      
          delete parent;
          delete child;
      
          return a.exec();
      }
      

      ================= myparentclass.h ===================

      #ifndef MYPARENTCLASS_H
      #define MYPARENTCLASS_H
      
      #include <QObject>
      
      class MyParentClass : public QObject
      {
          Q_OBJECT
      public:
          explicit MyParentClass(QObject *parent = 0);
          ~MyParentClass();
      
      signals:
      
      public slots:
      };
      
      #endif // MYPARENTCLASS_H
      

      ================= myparentclass.cpp ====================

      #include "myparentclass.h"
      #include <QCoreApplication>
      
      MyParentClass::MyParentClass(QObject *parent) : QObject(parent)
      {
      
      }
      
      MyParentClass::~MyParentClass()
      {
          qDebug("MyParentClass destructor");
          QCoreApplication::quit();
      }
      

      ================== mychild.h ========================

      #ifndef MYCHILD_H
      #define MYCHILD_H
      
      #include <QObject>
      
      class MyChild : public QObject
      {
          Q_OBJECT
      public:
          explicit MyChild(QObject *parent = 0);
          ~MyChild();
      
      signals:
      
      public slots:
      };
      
      #endif // MYCHILD_H
      

      ==================== mychild.cpp =====================

      #include "mychild.h"
      
      MyChild::MyChild(QObject *parent) : QObject(parent)
      {
      }
      
      MyChild::~MyChild()
      {
          qDebug("MyChild destructor");
          this->parent()->deleteLater();
      }
      

      I have added all these files into the Qt project:
      alt text

      But when I build it, I got errors:
      alt text

      I searched some previous threads which suggest clean and rebuild, but it does not work.

      The Qt I am using is 5.10.0 and the Qt Creator is 4.5.0. The OS is Windows 7. I have Visual Studio 2015 installed so I want to use VS to compile. This is the kit configuration:
      alt text

      So, what am I missing? How to fix the errors? Thank you.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @zzzhhhzzzhhh
      Hi
      Code looks correct and it seems to complain about the construtor.

      Normally, it can be resolved by
      deleting the build folder completely and then rebuild all.

      You can test your Kits by making a default GUI project and see if that runs.

      1 Reply Last reply
      4
      • yuvaramY Offline
        yuvaramY Offline
        yuvaram
        wrote on last edited by
        #3

        Hi @zzzhhhzzzhhh

        adding few words, in main function "delete child" is not required. As parent "parent" will take of deleting child.
        Parent Child relationship in Qt

        Yuvaram Aligeti
        Embedded Qt Developer
        : )

        1 Reply Last reply
        4
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          To expand on @yuvaram good catch,
          i consider this a "must read" for c++ programmers new
          to Qt.
          http://doc.qt.io/qt-5/objecttrees.html

          1 Reply Last reply
          1
          • Z Offline
            Z Offline
            zzzhhhzzzhhh
            wrote on last edited by
            #5

            Thank you all so much! After I deleted the folder "build-HelloWorld-Desktop_Qt_5_10_0_MSVC2015_64bit-Debug" and rebuild the project, all linking errors are gone. Also, I will read the links you gave me and pay more attention to this issue later. Thank you again!

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved