use of undeclared identifier 'connect'

btzs picture btzs · Nov 12, 2013 · Viewed 11.5k times · Source

me again! :-[

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 me this error? :-)

thanks in advance

Answer

Ryeeeeee picture Ryeeeeee · Jan 19, 2015

please ensure Downloader does inherit from QObject.

class Downloader : public QObject{

}