tags:

views:

508

answers:

2

Hello,

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!

+3  A: 

Hey,

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

Andy M
Hey,thanks for your answer! It works that way as it should, but i think its not as "sexy" as a solution without an "connector".Maybe its just not possible. :/
Tim Demkowsky
Well since they're also using that way, I think it's not possible, at least at the moment! Glad it helped you...
Andy M
A: 

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.

hidden_4003