How do I modify a QLabel object in my UI outside of its slot?

372 views Asked by At

Just a short question:

I wish to edit the text of a QLabel object outside of its slot, depending on the value of a conditional statement unrelated to the widget. Research online has been inconclusive, so I would greatly appreciate if any of you could clarify how this is done.

Thanks!

Edit: I used Qt Designer to put the QLabel in my MainWindow class, meaning it was never formally declared within my MainWindow.cpp source code. Here is an explanation with code:

if (webcam.isOpened() == false)
{
    MainWindow::mainVideo.setText("Stream is offline.")
    /*mainVideo is my QLabel, I need to figure out how to access this if
     *it was placed into my UI via Qt Designer.
     */
}
1

There are 1 answers

2
eyllanesc On BEST ANSWER

Must be use:

if(condition){yourlabel.setText(your text);}

In your case:

if (!webcam.isOpened())
{
    ui->mainVideo->setText("Stream is offline.")
    /*mainVideo is my QLabel, I need to figure out how to access this if
     *it was placed into my UI via Qt Designer.
     */
}