Results 1 to 6 of 6

Thread: Updated to Creator 4.14 and 5.15.2 MSVC 2019 - now unable to generate main.moc

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2020
    Location
    Michigan
    Posts
    8
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default Updated to Creator 4.14 and 5.15.2 MSVC 2019 - now unable to generate main.moc

    I recently updated my Qt Creator to 4.14 and went from 5.14.2 MSVC2017 64bit to 5.15.2 MSVC2019 64 bit. My project had its command line arguments wiped out upon that update and now when I try to compile / run the app - I am receiving the following error:

    error: dependent 'debug\main.moc' does not exist.

    I have
    Qt Code:
    1. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    on the last line of my main.cpp file

    I have cleaned, ran qmake, built over and over again yet I can't seem to solve this issue (which did not happen while using MSVC2017) I use the Network Download example but have most of the code in a separate .cpp file versus having everything in my main.cpp. Nothing has changed in the code from using MSVC2017 and MSVC2019 so I am not quite sure why this would stop working?

    Any assistance would be greatly appreciated.
    Last edited by luckachi; 28th December 2020 at 19:56.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,240
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Updated to Creator 4.14 and 5.15.2 MSVC 2019 - now unable to generate main.moc

    Any assistance would be greatly appreciated.
    Why would you have a "main.moc" file in the first place? .moc files are typically generated by the MOC compiler when processing a header file that contains the declaration of a class derived from QObject and which contains the Q_OBJECT macro. These types of classes are not typically declared in a .cpp file, especially main.cpp. Usually main.cpp is just a few lines of code containing the main() function that kicks off the app's execution.

    This was probably an error you made long ago when first making the project, something that left behind a main.moc file in your debug build directory that didn't get removed during a make clean or rebuild. I am pretty sure that if you simply comment out that line, your project will build, and if it does, delete the line altogether.

    versus having everything in my main.cpp
    Edit - just noticed this. This almost certainly points to a previous version of the project where you had a QObject-based class defined in main.cpp that left behind some junk when you moved the class declaration out into its own file.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2020
    Location
    Michigan
    Posts
    8
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Updated to Creator 4.14 and 5.15.2 MSVC 2019 - now unable to generate main.moc

    Quote Originally Posted by d_stranz View Post
    Why would you have a "main.moc" file in the first place? .moc files are typically generated by the MOC compiler when processing a header file that contains the declaration of a class derived from QObject and which contains the Q_OBJECT macro. These types of classes are not typically declared in a .cpp file, especially main.cpp. Usually main.cpp is just a few lines of code containing the main() function that kicks off the app's execution.

    This was probably an error you made long ago when first making the project, something that left behind a main.moc file in your debug build directory that didn't get removed during a make clean or rebuild. I am pretty sure that if you simply comment out that line, your project will build, and if it does, delete the line altogether.
    This came from the Network Download example where all of the code is placed in the main.cpp file with #include main.moc at the bottom. I ended up moving all the contents from the Network Download example into its own .cpp file (filedownloader.cpp) to keep everything separate and never had an issue with the project running so I thought I had done everything correctly. It wasn't until I updated everything where I started to run into issues.

    When I just comment out #include "main.moc" I receive the following errors:

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

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

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

    debug\misin.exe:-1: error: LNK1120: 3 unresolved externals



    I tried to move the lines below to a separate header file (filedownloder.h) but I receive an error that reads Download of {file names} failed: Error while downloading : Size failed: Unable to find file

    Qt Code:
    1. #include <QtCore>
    2. #include <QtNetwork>
    3.  
    4. #include <cstdio>
    5.  
    6. QT_BEGIN_NAMESPACE
    7. class QSslError;
    8. QT_END_NAMESPACE
    9.  
    10. using namespace std;
    11.  
    12. class DownloadManager: public QObject
    13. {
    14. Q_OBJECT
    15. QNetworkAccessManager manager;
    16. QVector<QNetworkReply *> currentDownloads;
    17.  
    18. public:
    19. DownloadManager();
    20. void doDownload(const QUrl &url);
    21. static QString saveFileName(const QUrl &url);
    22. bool saveToDisk(const QString &filename, QIODevice *data);
    23. static bool isHttpRedirect(QNetworkReply *reply);
    24.  
    25. public slots:
    26. void execute();
    27. void downloadFinished(QNetworkReply *reply);
    28. void sslErrors(const QList<QSslError> &errors);
    29. };
    To copy to clipboard, switch view to plain text mode 


    Everything was working fine until this update
    Last edited by luckachi; 29th December 2020 at 15:15.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,240
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Updated to Creator 4.14 and 5.15.2 MSVC 2019 - now unable to generate main.moc

    Everything was working fine until this update
    Almost certainly because at some point you built your project when all of the code was still in main.cpp, it created the main.moc file, and that file was still hanging around.

    What is happening in this case seems to be that either MOC is not processing the header file where you have defined the DownloadManager class, 2) the cpp file generated by the MOC compiler is not being compiled by C++, or 3) the obj file produced by the compiler is not being linked into the executable.

    Make sure that your Qt Creator .pro file contains the name of your DownloadManager class header file in the HEADERS line, and then run qmake again before rebuilding.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 17th July 2013, 09:26
  2. unable to generate action in popup menu
    By Chinmoy in forum Newbie
    Replies: 1
    Last Post: 17th March 2011, 08:38
  3. Replies: 1
    Last Post: 21st September 2010, 08:58
  4. tableWidget created in Qt Creator not updated
    By binaural in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2009, 21:50
  5. Qt4.3 and MSVC++ 2005 - unable to install Qt
    By nitor in forum Installation and Deployment
    Replies: 12
    Last Post: 25th July 2007, 21:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.