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. QT QSerialPort and QTcpSocket working together
Qt 6.11 is out! See what's new in the release blog

QT QSerialPort and QTcpSocket working together

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k 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.
  • V Offline
    V Offline
    vahidnateghi
    wrote on last edited by
    #1

    I'm writing a medium program where it is supposed to get some packages from a program in one computer (A) via TCP protocol and send it to another machine(B) using the serial port.

    This is generally what I did to have them all together:

    @class TcpSerial : public QObject
    {
    Q_OBJECT
    private:
        QSerialPort *serialGate;
        guiCommand *Command;
        tcpReceiver *TCP;  \\A seperate class I wrote which can do basic TCP actions
    public:
        antennaDataReceiver();
    public slots:
        void dataReceivedFromSerial();
        void send_to_serial();
    }
    

    @
    They need to have some sort of communication as to give Command to each other. Now I have a problem managing the Thread issue here. I tried different approaches but I got different errors each time:

    1.Defining a new Thread using QThread and moving one of them into a seperate thread

    @ socket notifiers cannot be disabled/enabled from another thread@
    2.Moving the tcpReceiver to my class thread.
    3.Leaving them alone to run on their own threads.

    @ QObject: Cannot create children for a parent that is in a different thread.
    //and the program hangs out, I checked in this situation both tcpReceiver and serialSender are running in the same thread@

    What is you suggestion for handling this situation? Thank you in advance.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, as QSerialPort and QTcpSocket both provide
      asynchronous API, there is no need to create your own thread in normal cases.

      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