我正在尝试在qt中编写一个简单的下载程序。它基于这个例子: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 );
}
但是我收到以下错误:
/Users/name/ssl/downloader.cpp:19: error: use of undeclared identifier 'connect'
connect( qnam, SIGNAL( finished( QNetworkReply *) ), this, SLOT( replyFinished( QNetworkReply * ) ) );
你们有人能解释我这个错误吗? : - )
提前致谢
答案 0 :(得分:9)
请确保Downloader继承自QObject。
class Downloader : public QObject{
}