Important: Please read the Qt Code of Conduct -

[Solved]: Two different handler for same ready read signal in serial communication.

  • I am working with USB port as well as D-sub port(both are serial ports) at a time.
    Does anybody knows how to make two handler for same ready read signal in serial communication? May be identifying the ports which generates ready read signals..!!!

    Thanks in advance.

  • I just started working on it (Linux), and I am using "QtSerialPort":
    also "getting it to work":

  • I am using qextserialport (third party library) for serial communication.

  • Moderators

    Why don't you have one slots per port (connected to one read-ready signa)l. Those extract the data from the port and put it into a QByteArray which is then handed over to another method that does the actual processing?

  • That's exactly my point. How will I come to know that which port has generated the ready read signal?

    Actually, I am using USB port for some modules and D-sub port for to connect another industrial PC (same as normal computer) and I have to use both at a time. Now to work with both serial ports at a time, How to differentiate both? so that I can identify port which has generated ready read signal and can use appropriate handler.

    Thanks for you reply.

  • Moderators

    You connect the one object's readReady signal to one slot and the other object's readReady signal to another one. I am afraid I do not understand the question:-)

  • Mine agenda was to use only one object for serial communication as I have developed few common functions like OpenPort(), WriteData()...
    If I use more objects then there is no use of my common functions as I have to check weather perticular port is opened or not..!!!
    qint64 SerialPort::WriteData(QString message)
    QByteArray msg_ascii = message.toAscii();
    qint64 total=port->write(msg_ascii,msg_ascii.length());
    return 0;
    [edit, code tags added, koahnig]

  • I guess you are confusing class and object in your posting.
    A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

    An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.[/quote] This is copied from "here":

    What you want to do is having a common class definition with a method handling in both cases the readyRead signal.

    You could have something similar to this:
    class MySerialClass : public QExtSerialPort
    public slots:
    void sltReadyReadHandling (...);

    In your application you may have then:
    MySerialClass UsbPort;
    MySerialClass DSubPort;


  • Thanks kohnig,

    I solved the problem as well as confusion..!!!

Log in to reply