Hi..
I got these errors when I tried to use QObject in my class
moc_Download.cpp:42: error: `staticMetaObject' is not a member of `QRunnable'
moc_Download.cpp:58: error: `qt_metacast' is not a member of `QRunnable'
moc_Download.cpp:63: error: `qt_metacall' is not a member of `QRunnable'
#ifndef DOWNLOAD_H
#define DOWNLOAD_H
#include <QtCore>
#include <QtGui>
#include <QtNetwork>
class Download
: public QRunnable,
public QObject{
Q_OBJECT
public:
void run();
void updateDataReadProgress(int bytesRead, int totalBytes);
private:
int size;
QNetworkAccessManager *manager;
bool httpRequestAborted;
int httpGetId;
private slots:
void replyFinished(QNetworkReply* reply);
};
#endif // DOWNLOAD_H
#ifndef DOWNLOAD_H
#define DOWNLOAD_H
#include <QtCore>
#include <QtGui>
#include <QtNetwork>
class Download : public QRunnable, public QObject
{
Q_OBJECT
public:
Download(QString url, int size);
void run();
void updateDataReadProgress(int bytesRead, int totalBytes);
QLabel *label;
QProgressBar *progressBar;
QFile *file;
QHttp *http;
private:
QString url;
int size;
QNetworkAccessManager *manager;
bool httpRequestAborted;
int httpGetId;
private slots:
void replyFinished(QNetworkReply* reply);
};
#endif // DOWNLOAD_H
To copy to clipboard, switch view to plain text mode
#include "Download.h"
Download
::Download(QString url,
int size
) : QRunnable
(){
this->url = url;
this->size = size;
manager
= new QNetworkAccessManager
(new QObject);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}
void Download::run()
{
qDebug() << size;
progressBar->setValue(size*2);
}
void Download::updateDataReadProgress(int bytesRead, int totalBytes)
{
if (httpRequestAborted)
{
return;
}
progressBar->setMaximum(totalBytes);
progressBar->setValue(bytesRead);
}
void Download::replyFinished(QNetworkReply *reply)
{
qDebug() << "I'm in the reply";
}
#include "Download.h"
Download::Download(QString url, int size) : QRunnable()
{
this->url = url;
this->size = size;
manager = new QNetworkAccessManager(new QObject);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}
void Download::run()
{
qDebug() << size;
progressBar->setValue(size*2);
}
void Download::updateDataReadProgress(int bytesRead, int totalBytes)
{
if (httpRequestAborted)
{
return;
}
progressBar->setMaximum(totalBytes);
progressBar->setValue(bytesRead);
}
void Download::replyFinished(QNetworkReply *reply)
{
qDebug() << "I'm in the reply";
}
To copy to clipboard, switch view to plain text mode
#include "MainWindow.h"
#include "Download.h"
{
setupUi(this);
QVector<QString> files;
files.append("http://www.google.com");
files.append("http://www.google.com");
files.append("http://www.google.com");
files.append("http://www.google.com");
int size = files.size();
for (int i=0; i<size; i++)
{
progressBar
[i
] = new QProgressBar(scrollAreaWidgetContents
);
progressBar[i]->setTextVisible(false);
label
[i
] = new QLabel(scrollAreaWidgetContents
);
layoutScroll->addWidget(label[i]);
layoutScroll->addWidget(progressBar[i]);
}
QList<Download *> runners;
for (int i=0; i<size; i++)
{
Download *d = new Download("a", i);
d->label = label[i];
d->label->setText(tr("Fail: %1").arg(i));
d->progressBar = progressBar[i];
d->setAutoDelete(false);
QThreadPool::globalInstance()->start(d);
runners << d;
}
}
#include "MainWindow.h"
#include "Download.h"
MainWindow::MainWindow(QWidget *parent) : QDialog(parent)
{
setupUi(this);
QVector<QString> files;
files.append("http://www.google.com");
files.append("http://www.google.com");
files.append("http://www.google.com");
files.append("http://www.google.com");
int size = files.size();
QProgressBar *progressBar[size];
QLabel *label[size];
for (int i=0; i<size; i++)
{
progressBar[i] = new QProgressBar(scrollAreaWidgetContents);
progressBar[i]->setTextVisible(false);
label[i] = new QLabel(scrollAreaWidgetContents);
layoutScroll->addWidget(label[i]);
layoutScroll->addWidget(progressBar[i]);
}
QList<Download *> runners;
for (int i=0; i<size; i++)
{
Download *d = new Download("a", i);
d->label = label[i];
d->label->setText(tr("Fail: %1").arg(i));
d->progressBar = progressBar[i];
d->setAutoDelete(false);
QThreadPool::globalInstance()->start(d);
runners << d;
}
}
To copy to clipboard, switch view to plain text mode
If you guys need anymore information, I'll post more, just let me know, thanks in advance
Bookmarks