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 gui-show many data from serial port to specific places
Forum Updated to NodeBB v4.3 + New Features

Qt gui-show many data from serial port to specific places

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 249 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.
  • B Offline
    B Offline
    Bored
    wrote on last edited by
    #1

    Im using Qt to create GUI for temperature and humidity, i have the data send from serialport .
    However, the data for example was writen like this "28.0095.00". How can i show them in spercific label on the dialog window?

    JonBJ 1 Reply Last reply
    0
    • B Bored

      Im using Qt to create GUI for temperature and humidity, i have the data send from serialport .
      However, the data for example was writen like this "28.0095.00". How can i show them in spercific label on the dialog window?

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

      @Bored If that is a string then just use QLabel::setText(thatString). If not then clarify your question.

      B 1 Reply Last reply
      0
      • JonBJ JonB

        @Bored If that is a string then just use QLabel::setText(thatString). If not then clarify your question.

        B Offline
        B Offline
        Bored
        wrote on last edited by
        #3

        @JonB the number "28.0095.00" in qDebug is the tem=28.00 and hum=95.00 i get from sensor using arduino, i don't know how to show it on my dialog window each one in each different label.

        JonBJ C 2 Replies Last reply
        0
        • B Bored

          @JonB the number "28.0095.00" in qDebug is the tem=28.00 and hum=95.00 i get from sensor using arduino, i don't know how to show it on my dialog window each one in each different label.

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

          @Bored
          qDebug() output is not clear as to what you actually receiving. Do they arrive as strings? As numbers? How are they separated? Only you know, we do not. Get the two separate values, however you do that, and set the text of the two desired labels correspondingly. If they are numbers rather than strings something like QString::number() will convert them to strings for adding.

          1 Reply Last reply
          0
          • B Bored

            @JonB the number "28.0095.00" in qDebug is the tem=28.00 and hum=95.00 i get from sensor using arduino, i don't know how to show it on my dialog window each one in each different label.

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            @Bored Here are my assumptions:

            • You receive 10 or 11 bytes for each reading.
            • The bytes are in a QByteArray I will call ba.
            • The bytes are:
              • five digits "TT.tt" representing the temperature in some unspecified units
              • five digits "HH.hh" representing the humidity in percent
              • optionally a '\0' character
            • The output widgets are QLabels in your UI.
            • You want to display the values exactly as received.

            Then, verbosely:

            QByteArray ba("28.0095.00");
            const QString temperature = ba.left(5);  // or ba.first(5) in Qt 6
            const QString humidity    = ba.mid(5, 5); // or ba.sliced(5, 5) in Qt 6
            ui->temperatureLabel = temperature;
            ui->humidityLabel = humidity;
            
            1 Reply Last reply
            0
            • B Bored has marked this topic as solved on

            • Login

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