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. [SOLVED] Unresolved External Symbol Error
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Unresolved External Symbol Error

Scheduled Pinned Locked Moved General and Desktop
10 Posts 6 Posters 12.8k 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.
  • P Offline
    P Offline
    Paawan
    wrote on last edited by
    #1

    Hi All,

    I am getting three errors when I try to pass an object to another class. The errors are:

    film.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Film::metaObject(void)const " (?metaObject@Film@@UEBAPEBUQMetaObject@@XZ)

    film.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __cdecl Film::qt_metacast(char const *)" (?qt_metacast@Film@@UEAAPEAXPEBD@Z)

    film.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __cdecl Film::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Film@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)

    All have "File not found: film.obj" under the errors in red.

    The class that I am trying to pass:

    @class Film: public QObject
    {
    Q_OBJECT

    Q_PROPERTY(QString title READ getTitle  WRITE setTitle)
    

    Q_PROPERTY(QString director READ getDirector WRITE setDirector )
    Q_PROPERTY(int duration READ getDuration WRITE setDuration )
    Q_PROPERTY(QDate releaseDate READ getReleaseDate WRITE setReleaseDate)

    public:
    Film(); // Default constructor
    Film(QString t,int dur, QString dir, QDate r ); // Constructor
    void setTitle(QString t);
    void setDuration (int dur);
    void setDirector (QString dir);
    void setReleaseDate (QDate r);

    QString getTitle();
    QString getDirector();
    int getDuration();
    QDate getReleaseDate();
    

    private:
    QString title;
    int duration;
    QString director;
    QDate releaseDate;

    };@

    The class that has to receive it:

    Header file:

    @#include <QtCore>
    #include <QTextStream>
    #include <QFile>
    #include <QString>
    #include "film.h"

    class FilmWriter
    {

    public:
    FilmWriter();
    FilmWriter(Film * myFilm);

    private:

    };
    @

    The CPP File:

    @FilmWriter::FilmWriter(Film * myyFilm){

    //Film myFilm(myyFilm);
    QString mFileName = "F:/myFilms.txt"; //File to store the Films
    
    QFile mFile&#40;mFileName&#41;;
    
    if (!mFile.open(QFile::WriteOnly | QFile::Text&#41;)
    
    {
        qDebug()<< "Cannot open File";
        return;
    }
    
    QTextStream out(&mFile);
    
    
    
    out<<myyFilm->getTitle();
    

    out<<myyFilm->getDirector();

    out<<myyFilm->getDuration();
    
    out<<myyFilm->getReleaseDate().toString();
    

    /*

    out<< myFilm.getTitle();
    out<< myFilm.getDirector();
    out<< myFilm.getDuration();
    out<<myFilm.getReleaseDate().toString();
    
    
    */
    
    mFile.flush();
    mFile.close();
    

    }
    @

    Please help.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you re-run qmake after adding Q_OBJECT to your Film class ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Paawan
        wrote on last edited by
        #3

        Sorted. Thanks for the help.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome,

          Don't forget to update the thread's title prepending solved so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • LordonL Offline
            LordonL Offline
            Lordon
            wrote on last edited by
            #5

            Hi, Im new in QT. Can you write more informations how to re-run qmake .
            I have one more question. Is the qmake file the same as MyProject.pro ?? - the .pro file in my project ?

            mrjjM 1 Reply Last reply
            0
            • LordonL Lordon

              Hi, Im new in QT. Can you write more informations how to re-run qmake .
              I have one more question. Is the qmake file the same as MyProject.pro ?? - the .pro file in my project ?

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

              @Lordon
              Hi and welcome
              Yes MyProject.pro is the qmake file.

              • To re-run it means to go to build menu and select "Run qmake" to be sure.

              In rare cases , you might also delete your build folder for things to be really remade.
              To find build folder, look in "projects" tab, and its just Build directory.
              This folder contains auto generated files and safe to delete all files in.
              So you exploer to go there and delete all in those cases.

              1 Reply Last reply
              0
              • LordonL Offline
                LordonL Offline
                Lordon
                wrote on last edited by
                #7

                Oh, my mistake. I forgot say, that Im working in VisualStudio. There is not something like "Run qmake". Is there any way to do this in Visual Studio ?

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

                  Oh. I never used VS with Qt so Im not sure.

                  Normally you also install the Qt VS plugin that handles all this.

                  Since VS dont really use .pro files i assume you have this plugin as
                  you sound you can compile.

                  Did you install this plugin ?
                  http://doc.qt.io/vs-addin/
                  http://download.qt.io/official_releases/vsaddin/qt-vs-addin-1.2.5.exe.mirrorlist

                  If not, you will have that issue that Qt want a tool called moc.exe run on normal compiles.
                  This tools makes connect and a lot of other core features work.

                  If its not run, then you will see errors like in this thread.

                  What version of VS are you using ?
                  Make sure it all matches with version etc.

                  1 Reply Last reply
                  0
                  • LordonL Lordon

                    Oh, my mistake. I forgot say, that Im working in VisualStudio. There is not something like "Run qmake". Is there any way to do this in Visual Studio ?

                    K Offline
                    K Offline
                    KeithS
                    wrote on last edited by
                    #9

                    @Lordon
                    You don't need to run qmake if using Visual Studio with the Qt VS plugin, as VS will set up custom build steps for your .ui files (to run uic) and .h files that use Q_OBJECT (to run moc).

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      Xahon
                      wrote on last edited by Xahon
                      #10

                      I have the same issue too, but with Visual Studio + Cmake setup.
                      There is something that cmake does about the moc:
                      [1/5] Automatic MOC and UIC for target MyProject
                      [2/5] Building CXX object Test05\CMakeFiles\MyProject.dir\MyProject_autogen\mocs_compilation.cpp.obj
                      [3/5] Building CXX object Test05\CMakeFiles\MyProject.dir\src\Main.cpp.obj
                      [4/5] Building CXX object Test05\CMakeFiles\MyProject.dir\src\MainWindow.cpp.obj
                      [5/5] Linking CXX executable bin\MyProject.exe

                      and the same errors in linking stage

                      In the build directory, after some searching, I found only a file called "mocs_compilation.cpp", but that file contains only

                      // This file is autogenerated. Changes will be overwritten.
                      // No files found that require moc or the moc files are included
                      enum some_compilers { need_more_than_nothing };
                      

                      If I understand it correctly - moc should create an Q_OBJECT macro implementation for my class and that should be linked in final executable, but that file is not generated

                      UPD. A solution found
                      I also needed to add header files as source files in cmake add_library/add_executable functions, e.g. add_executable(MyProject "include/HeaderFileContaining_Q_OBJECT_Macro.hpp"). It seems weird because there is no need to "include" headers that way, it just doesn't make sense in non-qt cmake development

                      1 Reply Last reply
                      0

                      • Login

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