ctote
17th February 2010, 21:54
Hey everyone,
I'm using QtCreator to design my project. I need to send a datagram every 5 seconds out of a udpSocket. What i'm trying to do is this: When a user clicks the Enable button, it starts a timer - every 5 seconds the datagram is sent out the updSocket.
Here's my code -
void jaus::startBroadcasting()
{
connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram()));
ui->enableButton->setText("Disable");
ui->enableButton->setEnabled(false);
timer->start(5000);
}
void jaus::sendDatagram()
{
QByteArray message = "Hello.";
udpSocket->writeDatagram(message, QHostAddress::LocalHost, 9000);
}
I have the Enable button anchored to the startBroadcasting() slot. But when I click the button, the program blows up -- it doesn't do that when I take out the connect command and the timer->start() command.
Thanks for any help
I'm using QtCreator to design my project. I need to send a datagram every 5 seconds out of a udpSocket. What i'm trying to do is this: When a user clicks the Enable button, it starts a timer - every 5 seconds the datagram is sent out the updSocket.
Here's my code -
void jaus::startBroadcasting()
{
connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram()));
ui->enableButton->setText("Disable");
ui->enableButton->setEnabled(false);
timer->start(5000);
}
void jaus::sendDatagram()
{
QByteArray message = "Hello.";
udpSocket->writeDatagram(message, QHostAddress::LocalHost, 9000);
}
I have the Enable button anchored to the startBroadcasting() slot. But when I click the button, the program blows up -- it doesn't do that when I take out the connect command and the timer->start() command.
Thanks for any help