How to change label value?
-
I would like to change textmessage in a while loop how can I get it? Now same value is coming screen only once.Although I print ethernetThread->buffer[i] to console in a while loop, different values are coming
In header file I havepublic slots: void messageSlot(); public: QLabel *radar_data_label;
In mainWindow.cpp
void MainWindow::messageSlot(){ int i=0; while(1){ QString textmessage = QString(QChar::fromLatin1(ethernetThread->buffer[i])); radar_data_label->setText(textmessage); radar_data_label->setStyleSheet("QLabel { font: 18pt; color : white; }"); i++; } }
-
@ELIF
You can't while you have awhile(1)
, which blocks the Qt event loop and updates to the display. (Not to mention, your code runs forever keeping incrementingi
, how doesethernetThread->buffer[i]
not error?)Use proper signals & slots to do your UI updating, when new characters are present in
ethernetThread->buffer[i]
, allowing the Qt event loop to be re-entered so it can show the updated text.And while I think of it, if
ethernetThread
is truly a thread you need to understand generally how to access/share data safely across threads before you go directly reading from buffers in one thread which another thread is writing to..... -
@ELIF
If you don't understand how to write signals & slots in Qt you won't get anywhere. You don't want someone else to write it for you, you need to know how to write it yourself. There are thousands of examples in the Qt docs, examples and out there on the web. You need to read and understand https://doc.qt.io/qt-5/signalsandslots.html for a start.