qt - Qt5 slot being called multiple times from a single emit statement -


i'm relatively new qt, have done little searching around. have base class handles udp broadcasting, , connect statements in constructor of class this:

networkconnection::networkconnection(qobject *parent)     : qobject(parent) // based on qobject     , m_server_search( new qudpsocket ) // our udp broadcast socket     , m_waiting_for_server( false )     , m_found_server( false ) {     qdebug() << "networkconnection::constructor";     connect( m_server_search, signal(readyread()), this, slot(serverresponse()), qt::uniqueconnection );     if ( m_server_search->bind( qhostaddress::anyipv4, (quint16)port_multicast, qudpsocket::shareaddress ) )     {         if ( m_server_search->joinmulticastgroup( qhostaddress( multicast_group ) ) )         {             connect( this, signal(broadcast(networkmessage)), this, slot(broadcast_message(networkmessage)), qt::uniqueconnection );             this->m_ping_timer = this->starttimer(2000);             qdebug() << "ping timer id=" << this->m_ping_timer;         } else qdebug() << "couldn't start multicast listener";     } else qdebug() << "couldn't bind multicast port" << port_multicast; } 

i set signal/slot interface broadcasting:

signals:     void serverfound();     void servernotfound();     void broadcast(networkmessage);  private slots:     void serverresponse();     void broadcast_message( networkmessage msg ); 

and broadcast_message looks this:

void networkconnection::broadcast_message( networkmessage msg ) {     qbytearray raw = msg.tostring();     qdebug() << "networkconnection::broadcast_message>" << raw;     if ( m_server_search->writedatagram( raw.data(), raw.size(), qhostaddress(multicast_group), (quint16)port_multicast ) < 1 ) qdebug() << "failed broadcast last message"; } 

my timer works well, , here code:

void networkconnection::timerevent(qtimerevent *event) {     qdebug() << "networkconnection::timerevent id" << event->timerid() << "(ping timer=" << this->m_ping_timer << ")";     if ( event->timerid() == this->m_ping_timer )     {         qdebug() << "networkconnection::pingforserver";         if ( m_waiting_for_server && !m_found_server )         {             qdebug() << "server not found!";             emit this->servernotfound();             return;         }         if ( !m_found_server )         {             qdebug() << "sending ping server";             networkmessage msg( m_software_guid, get_microseconds(), qstring("whoisaserver") );             emit this->broadcast( msg );             m_waiting_for_server = true;             m_found_server = false;         }     } } 

i text "sending pint server" once, broadcast_message outputs it's qdebug() multiple times.

i'm not explicitly using multiple threads, , can see i'm using qt::uniqueconnection, apparently having no affect?

so why slot called multiple times? i've tried debugging little , calling this->broadcast( ... ) without using emit, , still gets called multiple times.

edit: added counter broadcast_message slot, , gets called 340 times. there significance that?


Comments