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. QThread sync communication + one extra event
Forum Updated to NodeBB v4.3 + New Features

QThread sync communication + one extra event

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 363 Views
  • 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.
  • qtprogrammer123Q Offline
    qtprogrammer123Q Offline
    qtprogrammer123
    wrote on last edited by
    #1

    Hi,
    Im using QThread for sync QSerialPort communication - i need it. But i have one very long operation, and i dont wonna stop serial communication with 2 minutes timeout

    if (serial.waitForReadyRead(waitTimeout)) {
                QByteArray responseData = serial.readAll();
                while (serial.waitForReadyRead(10))
                 responseData += serial.readAll();
    

    I need some way to recive this one special operation in async way.

    QThread is blocked until next data send by wait condition

     mutex.lock();
     condition.wait(&mutex);
    

    I can recognize this anserw by data inside frame

    Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

    jsulmJ 1 Reply Last reply
    0
    • qtprogrammer123Q qtprogrammer123

      Hi,
      Im using QThread for sync QSerialPort communication - i need it. But i have one very long operation, and i dont wonna stop serial communication with 2 minutes timeout

      if (serial.waitForReadyRead(waitTimeout)) {
                  QByteArray responseData = serial.readAll();
                  while (serial.waitForReadyRead(10))
                   responseData += serial.readAll();
      

      I need some way to recive this one special operation in async way.

      QThread is blocked until next data send by wait condition

       mutex.lock();
       condition.wait(&mutex);
      

      I can recognize this anserw by data inside frame

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qtprogrammer123 said in QThread sync communication + one extra event:

      I need some way to recive this one special operation in async way.

      Then why do you use blocking calls? QSerialPort provides asynchronous API, use it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • qtprogrammer123Q Offline
        qtprogrammer123Q Offline
        qtprogrammer123
        wrote on last edited by qtprogrammer123
        #3

        Like i wrote it must be sync communication in other thread, application need it. I using serial in 5 places in code and all of them need take serial for communication with device and wait for anserw, anserw are similar and i cant recognize it. Only 6 operation not

        Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

        jsulmJ 1 Reply Last reply
        0
        • qtprogrammer123Q qtprogrammer123

          Like i wrote it must be sync communication in other thread, application need it. I using serial in 5 places in code and all of them need take serial for communication with device and wait for anserw, anserw are similar and i cant recognize it. Only 6 operation not

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @qtprogrammer123 I have no idea how you would use same serial port at the same time for synchronous and asynchronous communication...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • qtprogrammer123Q Offline
            qtprogrammer123Q Offline
            qtprogrammer123
            wrote on last edited by
            #5

            Its only one async operation - this command not block device, but i recive anserw after few minutes. Before that i wonna still use my sync communication for regular operation

            ----sync communication ---
            ----sync communication ---
            ...
            ----command with long period of anserw ---
            ...
            ----sync communication ---
            ....
            ....----command with long period of anserw response ---

            Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then use async everywhere.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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