Help needed on using readyRead signal !!



  • Hello friends, I am working on a project which involves using QTcpSocket and QSerialPort. So here I wanted to implement functions for both serial port and socket when data is available. I used readyRead signal for both socket and serialport seperately.

    It is like below,
    @
    connect(&serialPort,SIGNAL(QSerialPort::readyRead()),this,SLOT(serialReceived()));
    connect(&socket, SIGNAL(QTcpSocket::readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);

    void rescueOp::serialReceived()
    {
    // get the information
    QByteArray data = serialPort.readAll();

    // will write on console
    qDebug() << " Data in Serial Port: " << data;
    

    }

    void rescueOp::readyRead()
    {
    // get the information
    QByteArray Data = socket.readAll();

    // will write on console
    qDebug() << " Data in Socket: " << Data;
    

    }
    @

    Output is getting some error like
    @
    Connected to server
    QObject::connect: No such signal QTcpSocket::QTcpSocket::readyRead() in ../rescue_original/rescueop.cpp:61
    QObject::connect: (receiver name: 'rescueOp')
    Serial Port Opened
    @

    So the question is how can I use this readyRead signal for both of them without a clash.


  • Moderators

    Hi,

    Instead of
    @
    SIGNAL(QTcpSocket::readyRead())
    @

    use
    @
    SIGNAL(readyRead())
    @



  • Hello Splicer, I've tried that previously which doesn't work for two objects i.e. Serialport and Socket which is shown in below code. Is there any another way possible.??
    @
    connect(&serialPort,SIGNAL(readyRead()),this,SLOT(serialReceived()));
    connect(&socket, SIGNAL(readyRead()), this, SLOT(socketReceived()), Qt::DirectConnection);
    @


  • Moderators

    What do you mean by it is not working ?
    Doesn't the above code compile ?



  • No no, I mean to say that serialport and socket conflicts each other with the same readyRead signal.
    When a new data is arrived through socket/serialport readyRead signal is emitted. I cant understand what if going with that function, when serialport is not used and socket is used readyRead signal works as required and vice-versa. But if combinely used it wont get any output.


  • Moderators

    Thats strange. Those 2 are two different objects which are connected to different slots. Also you have a slot same as a signal
    @
    void rescueOp::readyRead()
    @

    change it to something else. For eg. onReadyRead()



  • These are the new lines, now socket works and serialport doesn't get any input. :(
    @
    connect(&socket, SIGNAL(readyRead()), this, SLOT(socketReceived()), Qt::DirectConnection);
    connect(&serialPort,SIGNAL(QSerialPort::readyRead()),this,SLOT(serialReceived()));
    @


  • Moderators

    Use
    @
    SIGNAL(readyRead())
    @

    for serialport also.


Log in to reply
 

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