QProgressbar and QNetworkReply signals

i'm writing an application in C++ with the Qt Framework. It should download a File over http and display the download progress with a QProgressbar - but I don't get that part to work!

Sample code:

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)));

If I run my code, the following error occurs:

QObject::connect: Incompatible sender/receiver arguments
QNetworkReplyImpl::downloadProgress(qint64,qint64) --> QProgressBar::setValue(int)

But the Qt docs for QNetworkReply say:

This signal is suitable to connecting to QProgressBar::setValue() to update the QProgressBar that provides user feedback.

What is wrong with my code and how do I get it working? I'm running Qt 4.5.3 under Linux.

Thanks for help and sorry for my english!

Answers


Yeah, it's right, you have to set matching arguments in your SIGNAL/SLOT methods... Anyway, in the Qt Examples And Demos, you can find the following code in the exemple "FTP Client" :

connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(updateDataTransferProgress(qint64, qint64)));

...

void FtpWindow::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
{
    progressDialog->setMaximum(totalBytes);
    progressDialog->setValue(readBytes);
}

You could copy that part and update your progress bar this way...

I would therefore propose :

connect(downloader, SIGNAL(downloadProgress(qint64,qint64)), pbar, SLOT(updateDataTransferProgress(qint64,qint64)));

I hope it helps you !

More info : http://qt.nokia.com/doc/4.6/network-qftp.html


I quote the documentation:

Exceptionally, if a signal has more parameters than the slot it is connected to, the additional parameters are simply ignored:

connect(ftp,
SIGNAL(rawCommandReply(int, const
QString &)),
        this, SLOT(checkErrorCode(int)));

In your case the problem actually was that parameter types didn't match since qint64 != int and it is impossible to accomplish the task without wrapper or type cast.


Need Your Help

Realloc() returning NULL when memory is available

c++ visual-c++ memory realloc

I have a c++ program running on a Windows 7 machine with 12GB memory.

How to store an int and boolean as a pair

java memory-management primitive-types

We have a number of properties in several classes where the property is presently an int and a boolean. The int is the value and the boolean is true if that int has been set.