Results 1 to 3 of 3

Thread: Qt Creator - signals/slots problem

  1. #1
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt Creator - signals/slots problem

    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 -

    Qt Code:
    1. void jaus::startBroadcasting()
    2. {
    3. connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram()));
    4. ui->enableButton->setText("Disable");
    5. ui->enableButton->setEnabled(false);
    6. timer->start(5000);
    7. }
    8.  
    9. void jaus::sendDatagram()
    10. {
    11. QByteArray message = "Hello.";
    12. udpSocket->writeDatagram(message, QHostAddress::LocalHost, 9000);
    13. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by ctote; 17th February 2010 at 22:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt Creator - signals/slots problem

    have you initialised the timer correctly? and be aware that if you call startBroadcasting twice, sendDatagram will be called twice every 5 seconds. So better put the connect statement in the c-tor where you initialise your timer.

  3. #3
    Join Date
    Jan 2010
    Posts
    73
    Thanks
    6
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Creator - signals/slots problem

    You may have to learn to do multiple things. For example:
    1. Deal with a timer calling a slot
    2. Deal with UDP messages

    If you are not absolutely certain that you have the UDP thing working, see what happens if you replace your UDP code with qDebug statements. In other words, try to test one thing at a time for your initial code.

Similar Threads

  1. Replies: 2
    Last Post: 28th August 2009, 07:12
  2. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 09:06
  3. Signals And Slots problem
    By ldiamond in forum Newbie
    Replies: 7
    Last Post: 23rd March 2008, 00:11
  4. Problem using SIGNALS/SLOTS
    By JimDaniel in forum Qt Programming
    Replies: 5
    Last Post: 10th September 2007, 04:59
  5. Problem with signals and slots
    By conexion2000 in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2006, 10:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.