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. Read Serial Data In QByteArray
Forum Update on Monday, May 27th 2025

Read Serial Data In QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 834 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.
  • M Offline
    M Offline
    Marco Flad
    wrote on last edited by
    #1

    every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug alt text
    when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
    so how to got all Message in QByte array like that "000011110000111100001111&"
    My code :

    void Widget::updateReceivedData()
    {
        
       inBuffer = arduino->readAll();
       qDebug() << inBuffer ;
    
        //inBuffer = arduino->readLine();
    
        //QByteArray datalog(arduino->readAll());
    
       //QByteArray data ;
      // data.append(arduino->readAll());
     
      //while (arduino->waitForReadyRead(10))
      //inBuffer += arduino->readAll();
    
        }
    
    
    aha_1980A 1 Reply Last reply
    0
    • M Marco Flad

      every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug alt text
      when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
      so how to got all Message in QByte array like that "000011110000111100001111&"
      My code :

      void Widget::updateReceivedData()
      {
          
         inBuffer = arduino->readAll();
         qDebug() << inBuffer ;
      
          //inBuffer = arduino->readLine();
      
          //QByteArray datalog(arduino->readAll());
      
         //QByteArray data ;
        // data.append(arduino->readAll());
       
        //while (arduino->waitForReadyRead(10))
        //inBuffer += arduino->readAll();
      
          }
      
      
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @Marco-Flad your serial data arrives in chunks of one or several bytes, but seldom the whole answer in one block.

      So you have to append the new data to your existing buffer until all data is received.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Are you receiving null chars in your message ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • V Offline
          V Offline
          vikas dhumal
          wrote on last edited by
          #3

          use readyRead() SIGNAL at the time of serial->open(QIODevice::ReadWrite)
          connect(serial, SIGNAL(readyRead()),this,SLOT(readSerialData()),Qt::UniqueConnection);
          where serial is an object QSerialPort *serial;
          readSerialData() is user defined slot function make it in header file like
          private slots:
          void readSerialData();
          and finally in readSerialData() function
          static QString readResponseReply = "";
          readResponseReply.append(serial->readAll());
          qDebug()<<"readResponseReply";
          try it in your source code

          Christian EhrlicherC 1 Reply Last reply
          -1
          • V vikas dhumal

            use readyRead() SIGNAL at the time of serial->open(QIODevice::ReadWrite)
            connect(serial, SIGNAL(readyRead()),this,SLOT(readSerialData()),Qt::UniqueConnection);
            where serial is an object QSerialPort *serial;
            readSerialData() is user defined slot function make it in header file like
            private slots:
            void readSerialData();
            and finally in readSerialData() function
            static QString readResponseReply = "";
            readResponseReply.append(serial->readAll());
            qDebug()<<"readResponseReply";
            try it in your source code

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @vikas-dhumal Sorry but converting some binary data into a QString is completely wrong here. What @SGaist asked is correct - when there is a null byte in there, qDebug() will not print what you expect. Therefore I would use inBuffer.toHex() to output the data for debugging.

            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
            4
            • M Marco Flad

              every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug alt text
              when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
              so how to got all Message in QByte array like that "000011110000111100001111&"
              My code :

              void Widget::updateReceivedData()
              {
                  
                 inBuffer = arduino->readAll();
                 qDebug() << inBuffer ;
              
                  //inBuffer = arduino->readLine();
              
                  //QByteArray datalog(arduino->readAll());
              
                 //QByteArray data ;
                // data.append(arduino->readAll());
               
                //while (arduino->waitForReadyRead(10))
                //inBuffer += arduino->readAll();
              
                  }
              
              
              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @Marco-Flad your serial data arrives in chunks of one or several bytes, but seldom the whole answer in one block.

              So you have to append the new data to your existing buffer until all data is received.

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              3
              • V Offline
                V Offline
                vikas dhumal
                wrote on last edited by
                #6

                ok so instead of QString read it in QByteArray

                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