[SOLVED] QUdpSocket readyRead() signal
-
Im having troubles seeing the readyRead() signal from a bound UDP socket. This is our current code -
The socket is created in our class constructor -
@
// create the actual socket
m_socket = new QUdpSocket(this);// connect activity signal for socket
connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
@We then ask our Acquisition class to "start" acquiring some data -
@
bool Acquisition::start()
{
bool ret = true;if (m_socket->bind(5000, QUdpSocket::ShareAddress)) { qDebug() << "Startup... " << m_socket->localAddress().toString() << m_socket->localPort(); connect(m_socket, SIGNAL(readyRead(void)), this, SLOT(dataReady(void))); } else { qDebug() << qt_error_string(); ret = false; } return ret;
}
@Slots -
@
void Acquisition::dataReady()
{
// dummy variables
QHostAddress host;
quint16 port;qDebug() << "dataReady";
// there is some valid data available from UDP
// keep reading until empty (same block size as sent)
while (m_socket->hasPendingDatagrams())
{
// write to our UDP circular buffer
m_socket->readDatagram((char*)m_udpbuffer.Write(), m_msgSize, &host, &port);
}
}
void Acquisition::socketStateChanged(QAbstractSocket::SocketState socketState)
{
qDebug() << "socketStateChanged - " << socketState;
}@
When debugging our code, we hit our socketStateCahnged slot, but we never hit our dataReady slot... We have confirmed with wireshark the fact that there is some data between the devices on the specified port...
UI Elements work as expected (signal/slots) so the mechanism behind all that seems to be ok...
Can anyone suggest what else I am missing?
Ubuntu 12.10 (64-bit)
Qt - 5.0.2
Using Qt Creator to build and debug - 2.7.0 -
socketStateChanged displays
@socketStateChanged - QAbstractSocket::BoundState @ -
Result is the same whether run from debugger, or from command line.
When using QUdpSocket, does the application need elevated privileges? (sudo)
-
For what its worth each datagram is received as expected when writing a winsock2 application (from a Win7_64bit machine)...
-
Does your start() routine print that bind() was successful?
Have you tried the bind() using the default BindMode?
Have you tried the bind() call that takes an explicit host address? -
yes, bind() is successful (and a signal is fired to indicate the socket changed state to bound)...
I have tried binding to an explicit host address, as well as QHostAddress::Any.
I have tried QUdpSocket::ShareAddress and QUdpSocket::DontShareAddress.
I have have tried wired and wireless adapters. -
Ok, found my problem.
The object I was using to control my acquisition was allocated on the stack, and was deleted before my QApplication.exec() routine was called... ie - I have no Udp class running!
7/7