9

I'm trying to write a simple downloader in qt. It's based on this example: http://www.ggkf.com/qt/qnetworkrequest-to-download-an-image

downloader.cpp:

void Downloader::GetImage( QString _url, QNetworkAccessManager *qnam ) {
    connect( qnam, SIGNAL( finished( QNetworkReply *) ), this, SLOT( replyFinished(   QNetworkReply * ) ) );

    QUrl url = QUrl( _url );
    QNetworkRequest request( url );

    qnam->get( request );
}

But I get the following error:

/Users/name/ssl/downloader.cpp:19: error: use of undeclared identifier 'connect'
connect( qnam, SIGNAL( finished( QNetworkReply *) ), this, SLOT( replyFinished( QNetworkReply * ) ) );

Can anyone of you explain to me this error?

rgettman
  • 176,041
  • 30
  • 275
  • 357
btzs
  • 1,048
  • 3
  • 14
  • 17

1 Answers1

14

please ensure Downloader does inherit from QObject.

class Downloader : public QObject{

}
Ryeeeeee
  • 156
  • 2
  • 4
  • 5
    @LorenzMeyer, yes, but this is a common issue faced by Qt newbies, and thus deserves an answer on its own, even if it was given in the comment. – SexyBeast Mar 11 '15 at 12:03
  • Just because it's old, doesn't (always) make it incorrect -- it's the first answer that pops up on google, and has immediately given me the correct answer. – Anonymouse Nov 01 '18 at 15:35