Yep...I should have specified "this" as the first argument in the invokeMethod() call. Seems to be working now. Here are some snippets:
UdpSocket::UdpSocket(QObject *parent) : QObject(parent)
{
bool rc;
// set up addresses.
m_addrRecv.setAddress(QHostAddress::AnyIPv4);
m_addrSend.setAddress(MCAST_GROUP);
rc = QMetaObject::invokeMethod(this, "sendDiscoveryMsgs", Qt::QueuedConnection);
}
void UdpSocket::sendDiscoveryMsgs()
{
qnil = QNetworkInterface::allInterfaces();
// for each viable interface, create and configure a socket.
for (it = qnil.begin(); it != qnil.end(); ++it)
{
sock = new QUdpSocket;
sock->bind(m_addrRecv, MCAST_PORT, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);
QObject::connect(sock, &QUdpSocket::readyRead, this, &UdpSocket::checkResponse);
m_sock = sock; // the send() below uses m_sock.
send(str);
}
}
void UdpSocket::checkResponse()
{
int rc = recv();
if (rc == 0) // got a valid response
{
if (m_msgStr.find(MsgTypeText[MSG_DISCOVERY_ACK]) != string::npos)
{
m_sock = qobject_cast<QUdpSocket *>(sender());
m_qni = new QNetworkInterface;
*m_qni = m_socketInterfaceMap[m_sock];
QObject::disconnect(m_sock, &QUdpSocket::readyRead, this, &UdpSocket::checkResponse);
QObject::connect(m_sock, &QUdpSocket::readyRead, this, &UdpSocket::recv);
QObject::connect(m_sock, &QUdpSocket::disconnected, this, &UdpSocket::reconnect);
}
}
}
I have a minor memory leak in that I don't destroy the unused sockets after I find the right one, but this way I don't have to maintain a list of the sockets while I'm trying to determine the "good" one.
Thanks for the help.