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. Why qDebug and plaintext gives different outputs?
QtWS25 Last Chance

Why qDebug and plaintext gives different outputs?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 189 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.
  • F Offline
    F Offline
    fatihsezgin
    wrote on last edited by
    #1

    Hello I'm kinda new in Qt and I'm working on gps data. My purpose is process the data that comes from gps.

    connect(serial,&QSerialPort::readyRead,this,&MainWindow::serialReceived);
    

    In sıgnal received slot, I'm printing the data in QPlainTextEdit gives me correct format of data.

    void MainWindow::serialReceived()
    {
    
        QByteArray byteArray;
        byteArray = serial->readAll();
        QString ba(byteArray);
    
        plainText->insertPlainText(ba);
    
        QTextCursor c = plainText->textCursor();
        c.movePosition(QTextCursor::End);
        plainText->setTextCursor(c);
    }
    

    Here is the GUI

    But when I print with qDebug() it outputs:

    "$GPGGA,102648.000,4059.7329,N,02"
    "843.3850,E,2,7,1.67,82.3,M,39.5,"
    "M,0000,000063\r\n$GPRMC,102648.00"
    "0,A,4059.7329,N,02843.3850,E,0.0"
    "3,290.70,050600,,,D
    6A\r\n"
    "$GPGGA,102649.000,4059.7329,N,02"
    "843.3850,E,2,7,1.67,82.3,M,39.5,"
    "M,0000,000062\r\n$GPRMC,102649.00"
    "0,A,4059.7329,N,02843.3850,E,0.0"
    "5,290.70,050600,,,D
    6D\r\n"

    I need to get the data in the form of QPlainTextEdit shows so I can parse the data.
    How can I achieve this ? Thanks.

    aha_1980A 1 Reply Last reply
    0
    • F fatihsezgin

      Hello I'm kinda new in Qt and I'm working on gps data. My purpose is process the data that comes from gps.

      connect(serial,&QSerialPort::readyRead,this,&MainWindow::serialReceived);
      

      In sıgnal received slot, I'm printing the data in QPlainTextEdit gives me correct format of data.

      void MainWindow::serialReceived()
      {
      
          QByteArray byteArray;
          byteArray = serial->readAll();
          QString ba(byteArray);
      
          plainText->insertPlainText(ba);
      
          QTextCursor c = plainText->textCursor();
          c.movePosition(QTextCursor::End);
          plainText->setTextCursor(c);
      }
      

      Here is the GUI

      But when I print with qDebug() it outputs:

      "$GPGGA,102648.000,4059.7329,N,02"
      "843.3850,E,2,7,1.67,82.3,M,39.5,"
      "M,0000,000063\r\n$GPRMC,102648.00"
      "0,A,4059.7329,N,02843.3850,E,0.0"
      "3,290.70,050600,,,D
      6A\r\n"
      "$GPGGA,102649.000,4059.7329,N,02"
      "843.3850,E,2,7,1.67,82.3,M,39.5,"
      "M,0000,000062\r\n$GPRMC,102649.00"
      "0,A,4059.7329,N,02843.3850,E,0.0"
      "5,290.70,050600,,,D
      6D\r\n"

      I need to get the data in the form of QPlainTextEdit shows so I can parse the data.
      How can I achieve this ? Thanks.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @fatihsezgin,

      readAll() does not care about line endings, so you get all data that has arrived at this point.

      You can try to use canReadLine() and readLine() (in a loop, as long as canReadLine() returns true), that should give you the lines you want.

      Regards

      Qt has to stay free or it will die.

      F 1 Reply Last reply
      2
      • aha_1980A aha_1980

        Hi @fatihsezgin,

        readAll() does not care about line endings, so you get all data that has arrived at this point.

        You can try to use canReadLine() and readLine() (in a loop, as long as canReadLine() returns true), that should give you the lines you want.

        Regards

        F Offline
        F Offline
        fatihsezgin
        wrote on last edited by
        #3

        @aha_1980 thank you :)

        1 Reply Last reply
        1

        • Login

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