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'
Qt Code:
  1. #ifndef DOWNLOAD_H
  2. #define DOWNLOAD_H
  3.  
  4. #include <QtCore>
  5. #include <QtGui>
  6. #include <QtNetwork>
  7.  
  8. class Download : public QRunnable, public QObject
  9. {
  10.  
  11. Q_OBJECT
  12.  
  13. public:
  14. Download(QString url, int size);
  15. void run();
  16.  
  17. void updateDataReadProgress(int bytesRead, int totalBytes);
  18.  
  19. QLabel *label;
  20. QProgressBar *progressBar;
  21.  
  22. QFile *file;
  23. QHttp *http;
  24.  
  25. private:
  26. QString url;
  27. int size;
  28.  
  29. QNetworkAccessManager *manager;
  30.  
  31. bool httpRequestAborted;
  32. int httpGetId;
  33.  
  34. private slots:
  35. void replyFinished(QNetworkReply* reply);
  36. };
  37.  
  38. #endif // DOWNLOAD_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "Download.h"
  2.  
  3. Download::Download(QString url, int size) : QRunnable()
  4. {
  5. this->url = url;
  6. this->size = size;
  7.  
  8. manager = new QNetworkAccessManager(new QObject);
  9. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
  10. }
  11.  
  12.  
  13. void Download::run()
  14. {
  15. qDebug() << size;
  16. progressBar->setValue(size*2);
  17. }
  18.  
  19. void Download::updateDataReadProgress(int bytesRead, int totalBytes)
  20. {
  21. if (httpRequestAborted)
  22. {
  23. return;
  24. }
  25.  
  26. progressBar->setMaximum(totalBytes);
  27. progressBar->setValue(bytesRead);
  28. }
  29.  
  30. void Download::replyFinished(QNetworkReply *reply)
  31. {
  32. qDebug() << "I'm in the reply";
  33. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "MainWindow.h"
  2. #include "Download.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) : QDialog(parent)
  5. {
  6. setupUi(this);
  7.  
  8. QVector<QString> files;
  9.  
  10. files.append("http://www.google.com");
  11. files.append("http://www.google.com");
  12. files.append("http://www.google.com");
  13. files.append("http://www.google.com");
  14.  
  15. int size = files.size();
  16.  
  17. QProgressBar *progressBar[size];
  18. QLabel *label[size];
  19.  
  20. for (int i=0; i<size; i++)
  21. {
  22. progressBar[i] = new QProgressBar(scrollAreaWidgetContents);
  23. progressBar[i]->setTextVisible(false);
  24.  
  25. label[i] = new QLabel(scrollAreaWidgetContents);
  26.  
  27. layoutScroll->addWidget(label[i]);
  28. layoutScroll->addWidget(progressBar[i]);
  29. }
  30.  
  31. QList<Download *> runners;
  32.  
  33. for (int i=0; i<size; i++)
  34. {
  35. Download *d = new Download("a", i);
  36.  
  37. d->label = label[i];
  38. d->label->setText(tr("Fail: %1").arg(i));
  39.  
  40. d->progressBar = progressBar[i];
  41.  
  42. d->setAutoDelete(false);
  43.  
  44. QThreadPool::globalInstance()->start(d);
  45. runners << d;
  46. }
  47. }
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