0 c++ networking qt qt4
我正在使用Qt Framework用C++编写应用程序.它应该通过http下载文件,并使用QProgressbar显示下载进度 - 但我没有让这部分工作!
示例代码:
QProgressBar* pbar = new QProgressBar();
//calls the website and returns the QNetworkReply*
QNetworkReply* downloader = Downloader->getFile();
connect(downloader, SIGNAL(downloadProgress(qint64,qint64)), pbar, SLOT(setValue(int)));
Run Code Online (Sandbox Code Playgroud)
如果我运行我的代码,会发生以下错误:
QObject::connect: Incompatible sender/receiver arguments
QNetworkReplyImpl::downloadProgress(qint64,qint64) --> QProgressBar::setValue(int)
Run Code Online (Sandbox Code Playgroud)
此信号适合连接到QProgressBar :: setValue()以更新提供用户反馈的QProgressBar.
我的代码出了什么问题,如何让它运行?我在Linux下运行Qt 4.5.3.
感谢您的帮助,对不起我的英语!
是的,它是正确的,您必须在SIGNAL/SLOT方法中设置匹配的参数...无论如何,在Qt示例和演示中,您可以在示例"FTP客户端"中找到以下代码:
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64, qint64)));
Run Code Online (Sandbox Code Playgroud)
...
void FtpWindow::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
{
progressDialog->setMaximum(totalBytes);
progressDialog->setValue(readBytes);
}
Run Code Online (Sandbox Code Playgroud)
您可以复制该部分并以这种方式更新进度条...
因此我建议:
connect(downloader, SIGNAL(downloadProgress(qint64,qint64)), pbar, SLOT(updateDataTransferProgress(qint64,qint64)));
Run Code Online (Sandbox Code Playgroud)
我希望它对你有所帮助!
更多信息:http://qt.nokia.com/doc/4.6/network-qftp.html