[SOLVED] readReady() signal not firing?



  • Hi all, I hav a simple UDP test program which follows several examples on the forum for sending and receiving datagrams. I am able to send datagrams to a remote laptop, but cannot receive them in my program. Some code:

    From test2.h:
    @class QUdpSocket;
    class QHostAddress;

    class test2 : public QObject
    {
    Q_OBJECT
    public:
    test2(QObject *parent, QQuickView *view)
    : QObject(parent), myDialog(view){

        switched = false;
    
        // create new UDP socket connection:
        udpSocket = new QUdpSocket(this);
        QHostAddress("10.1.10.62");
        udpSocket->bind(QHostAddress("10.1.10.62"), 4595);
        connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagram()));
    }
    

    public slots:
    void readPendingDatagram()
    {
    QByteArray buffer;
    buffer.resize(udpSocket->pendingDatagramSize());
    QHostAddress sender;
    quint16 senderPort;
    udpSocket->readDatagram(buffer.data(), buffer.size(), &sender, &senderPort);

        QQuickItem* object = myDialog->rootObject();
        QObject *textinput = object->findChild<QObject*>("textinput");
        textinput->setProperty("text", QString("Datagram Has Arrived.\r"));
        textinput->setProperty("text", buffer);
    
        return;
    }
    

    ....
    @

    When I send a datagram to my PC IP address, the datagram arrives (using a different receiver I'm able to get packets) but either my program isn't getting it, or I'm missing something. I tried binding to a different port, and tried binding after connect, still didn't work. Can someone shed some light? Thanks!



  • which IP address is the PC with your code running on it? and which IP address is the remote PC?

    Remote PC will send data to local PC (one with code on it) to a specific port. You "bind" to data coming in on the "target" IP address (i.e. the local PC IP address and port). Just check that you have that the right way around.

    There is no need to do anything other then bind() for the receive side. Check the status of the port to make sure the bind has worked.



  • Hi code_fodder (nice username btw)

    I solved it. I just bound the wrong address. Thanks!!!



  • ah ha, that old culprit... and then suddenly these udp sockets are nice and easy to use :)

    Also, you don't even have to connect to send stuff, you can just call the "send" function and specify a port / address and off it goes.

    You can specify the post as solved by changing the title to [SOLVED] .... title name....



  • Thanks Friend!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.