Qt gui-show many data from serial port to specific places
-
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? -
@Bored If that is a string then just use
QLabel::setText(thatString)
. If not then clarify your question. -
@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.
@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. -
@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.
@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;
-