use of undeclared identifier 'connect'
Asked Answered
C

1

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?

Carrier answered 12/11, 2013 at 9:39 Comment(3)
Are you missing a header file inclusion?Photothermic
Downloader does probably not inherit from QObject? It must.Prying
Thanks you two. It was the missing inheritance.Carrier
S
14

please ensure Downloader does inherit from QObject.

class Downloader : public QObject{

}
Smoothtongued answered 19/1, 2015 at 12:26 Comment(2)
@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.Calabresi
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.Yclept

© 2022 - 2024 — McMap. All rights reserved.