Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help needed on using readyRead signal !!
Forum Updated to NodeBB v4.3 + New Features

Help needed on using readyRead signal !!

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srikanth.koorma
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

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

      use
      @
      SIGNAL(readyRead())
      @

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        srikanth.koorma
        wrote on last edited by
        #3

        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);
        @

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

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

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            srikanth.koorma
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              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()

              157

              1 Reply Last reply
              0
              • S Offline
                S Offline
                srikanth.koorma
                wrote on last edited by
                #7

                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()));
                @

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  Use
                  @
                  SIGNAL(readyRead())
                  @

                  for serialport also.

                  157

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved