Qt gui-show many data from serial port to specific places
Solved
General and Desktop
-
@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 likeQString::number()
will convert them to strings for adding. -
@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;
-