Originally Posted by
d_stranz
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
#include <QtCore>
#include <QtNetwork>
#include <cstdio>
QT_BEGIN_NAMESPACE
class QSslError;
QT_END_NAMESPACE
using namespace std;
class DownloadManager
: public QObject{
Q_OBJECT
QNetworkAccessManager manager;
QVector<QNetworkReply *> currentDownloads;
public:
DownloadManager();
void doDownload
(const QUrl &url
);
static bool isHttpRedirect(QNetworkReply *reply);
public slots:
void execute();
void downloadFinished(QNetworkReply *reply);
void sslErrors(const QList<QSslError> &errors);
};
#include <QtCore>
#include <QtNetwork>
#include <cstdio>
QT_BEGIN_NAMESPACE
class QSslError;
QT_END_NAMESPACE
using namespace std;
class DownloadManager: public QObject
{
Q_OBJECT
QNetworkAccessManager manager;
QVector<QNetworkReply *> currentDownloads;
public:
DownloadManager();
void doDownload(const QUrl &url);
static QString saveFileName(const QUrl &url);
bool saveToDisk(const QString &filename, QIODevice *data);
static bool isHttpRedirect(QNetworkReply *reply);
public slots:
void execute();
void downloadFinished(QNetworkReply *reply);
void sslErrors(const QList<QSslError> &errors);
};
To copy to clipboard, switch view to plain text mode
Everything was working fine until this update
Bookmarks