[SOLVED] Unresolved External Symbol Error



  • 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


  • Lifetime Qt Champion

    Hi,

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



  • Sorted. Thanks for the help.


  • Lifetime Qt Champion

    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 :)



  • 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 ?


  • Qt Champions 2016

    @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.



  • 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 ?


  • Qt Champions 2016

    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.



  • @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).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.