@User123456 said in Display text for 4 seconds:
@JonB, I am using an old version, 4.5. I cannot just upgrade it since it is part of the requirements. Could you please give an example which will work on that version?
Given that you appear to be a beginner, I am surprised you are using such an old version of Qt. That must mean you have an existing, pretty ancient Qt code base to work with. I understand it's not automatic/trivial to upgrade, but it's shame. If you post any future questions in this forum you should state each time that you are using Qt4, as it may be relevant to answers. Bear in mind when looking through documentation/examples you may need to check for Qt 4 ones/compatibility.
Anyway, with an explicit method and not a lambda:
// header file:
private slots:
void onTimeout();
// cpp file:
void Dialog::onTimeout()
{
ui->LabelMessage->setText("");
}
// caller:
// next line connects using *new style* syntax, which is nicer...
QTimer::singleShot(4000, this, &Dialog::onTimeout);
// ... but if that doesn't work in Qt4 you can use *old style* syntax
QTimer::singleShot(4000, this, SLOT(onTimeout()));