3

I want to make a downloader by Qt. I hava a problem when I use QSignalMapper.

There is a signal in QNetworkReply, downloadProgress(qint64,qint64) I hava many download task, so I use QSignalMapper to process the signal. But how can I pass (qint64,qint64) to my own function?

I pass the id to my slot, but I loss (qint64,qint64)

connect(t->reply, SIGNAL(downloadProgress(qint64,qint64)), signalMapper, SLOT(map()));
signalMapper->setMapping(t->reply, id);

How to solve it?

honghaijie
  • 35
  • 1
  • 4

1 Answers1

2

You don't. From: http://qt-project.org/doc/qt-5.0/qtcore/qsignalmapper.html

This class collects a set of parameterless signals, and re-emits them with integer, string or widget parameters corresponding to the object that sent the signal.

As such, QSignalMapper is not deisgned to transfer parameters into other slots for you. If you want to do that, you need to either manually connect everything or otherwise do what this guy described: Can QSignalMapper be used to re-emit signals with multiple parameters? and reimplement QSignalMapper for your specific case.

If you use Qt 5, you can also do this: How to keep the source signal's parameters while using QSignalMapper?

Community
  • 1
  • 1
Aerius
  • 588
  • 5
  • 24