Originally Posted by
fatjuicymole
Ok, now I'm confused. The OP wanted to know which object emitted the signal that is connected to a particular slot. Assuming the slot had no arguments, why would you use sender() instead of QSignalMapper?
Here is an example:
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(buffer, SIGNAL(readyRead()), this, SLOT(readData()));
void SomeClass::readData() {
QIODevice *dev
= qobject_cast<QIODevice
*>
(sender
());
if(!dev) return;
qDebug() << dev->readAll();
}
QTcpSocket *socket = ...;
QBuffer *buffer = ...;
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(buffer, SIGNAL(readyRead()), this, SLOT(readData()));
void SomeClass::readData() {
QIODevice *dev = qobject_cast<QIODevice*>(sender());
if(!dev) return;
qDebug() << dev->readAll();
}
To copy to clipboard, switch view to plain text mode
You want to know which object emitted the signal because you want to access it and using QSignalMapper for this would be a bit silly.
Bookmarks