Search code examples
qtidentifierqt-connection

use of undeclared identifier 'connect'


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?


Solution

  • please ensure Downloader does inherit from QObject.

    class Downloader : public QObject{
    
    }