Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to: Tokenization (Splitting) QBytearray data?
Forum Updated to NodeBB v4.3 + New Features

How to: Tokenization (Splitting) QBytearray data?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 3 Posters 1.4k Views 2 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.
  • ahsan737A Offline
    ahsan737A Offline
    ahsan737
    wrote on last edited by
    #1

    Greetings,

    I am writing the Qt app, which receives the data over a Bluetooth connection. The data format is as following sensor_1,sensor_2,Sensor_3,\r\n. How the received data In QBytearray can be split into relevant variables without losing the data being received continuously.

    Best regards,
    Ahsan

    JonBJ 1 Reply Last reply
    0
    • ahsan737A ahsan737

      Greetings,

      I am writing the Qt app, which receives the data over a Bluetooth connection. The data format is as following sensor_1,sensor_2,Sensor_3,\r\n. How the received data In QBytearray can be split into relevant variables without losing the data being received continuously.

      Best regards,
      Ahsan

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @ahsan737
      You can split a QByteArray into a list on a character via QList<QByteArray> QByteArray::split(char sep) const. Or just use int QByteArray::indexOf(char ch, int from = 0) const. (Or convert to QString and use corresponding methods, if appropriate.) Buffer received data as necessary. This will have no impact on the continuous arrival of data.

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

        Hi,

        Cumulate the data until you have a full frame and then extract it and parse it.

        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
        1
        • ahsan737A Offline
          ahsan737A Offline
          ahsan737
          wrote on last edited by
          #4

          @JonB @SGaist

          I've tried this code to buffer incoming data, but it shows the error Segmentation Fault.
          How can I eliminate this error?

          incoming data: "315,317,1926,\r\n316,3"
          

          data is continuously being received, but currently, Bluetooth <characteristic changed> has received this chunk.

          void MainWindow::dataReceived(QByteArray data) 
          {
          buffer.setBuffer(&data);
          buffer.open(QIODevice::ReadWrite);
          while (buffer.canReadLine())
            {
               QByteArray line = buffer.readLine().trimmed();   //reading data from bluetooth channel
               QString list= QString::fromUtf8(line.constData(), line.length());    //reading incoming ASCII data
               
               ui->receivedTextEdit->append(list);
               ui->receivedTextEdit->append("\n");
            }
          }
          
          JonBJ 1 Reply Last reply
          0
          • ahsan737A ahsan737

            @JonB @SGaist

            I've tried this code to buffer incoming data, but it shows the error Segmentation Fault.
            How can I eliminate this error?

            incoming data: "315,317,1926,\r\n316,3"
            

            data is continuously being received, but currently, Bluetooth <characteristic changed> has received this chunk.

            void MainWindow::dataReceived(QByteArray data) 
            {
            buffer.setBuffer(&data);
            buffer.open(QIODevice::ReadWrite);
            while (buffer.canReadLine())
              {
                 QByteArray line = buffer.readLine().trimmed();   //reading data from bluetooth channel
                 QString list= QString::fromUtf8(line.constData(), line.length());    //reading incoming ASCII data
                 
                 ui->receivedTextEdit->append(list);
                 ui->receivedTextEdit->append("\n");
              }
            }
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @ahsan737 said in How to: Tokenization (Splitting) QBytearray data?:

            but it shows the error Segmentation Fault.

            Run from debugger and look at the stack trace window.

            ahsan737A 1 Reply Last reply
            0
            • JonBJ JonB

              @ahsan737 said in How to: Tokenization (Splitting) QBytearray data?:

              but it shows the error Segmentation Fault.

              Run from debugger and look at the stack trace window.

              ahsan737A Offline
              ahsan737A Offline
              ahsan737
              wrote on last edited by
              #6

              @JonB
              This is the stack trace screenshot

              segmentationFault.JPG

              JonBJ 1 Reply Last reply
              0
              • ahsan737A ahsan737

                @JonB
                This is the stack trace screenshot

                segmentationFault.JPG

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @ahsan737
                Who knows. This code no longer is the same as what you posted earlier. You don't show anything about buffer is. I don't know about the scope of your data. You do not verify the return result from buffer.open(). And so on.

                You can see for yourself from the stack trace that it's having trouble seeking for the `readLine(). You can use debugger to have a look at what's in the variables.

                ahsan737A 1 Reply Last reply
                0
                • JonBJ JonB

                  @ahsan737
                  Who knows. This code no longer is the same as what you posted earlier. You don't show anything about buffer is. I don't know about the scope of your data. You do not verify the return result from buffer.open(). And so on.

                  You can see for yourself from the stack trace that it's having trouble seeking for the `readLine(). You can use debugger to have a look at what's in the variables.

                  ahsan737A Offline
                  ahsan737A Offline
                  ahsan737
                  wrote on last edited by
                  #8

                  @JonB codes are the same, I just have removed while loop because it wasn't making any difference, the error is being caused at readLine.

                  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