how to show and hide Qlabel continuously on mainwindow
Hello all,
I am new to Qt, please tell me how to show and hide the Qlabel message continuously on my mainwindow...
Here is my code..
MainWindow.cpp
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
label=ui->label;
display();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::display()
{
while(1)
{
label->show();
sleep(1000);
label->hide();
}
}
when i run the program mainwindow is not comming...and no errors are comming..
Please help me..
Thank you.
Re: how to show and hide Qlabel continuously on mainwindow
First of all loop in MainWindow::display is "never ending story". Thus MainWindow constructor is blocking application.
Second UI need working event loop but You are blocking her. Read about QTimer.
Re: how to show and hide Qlabel continuously on mainwindow
Thank you for the reply....can u please provide with an example code..
I didn't get ur point..
Thanks in advance..
Re: how to show and hide Qlabel continuously on mainwindow
Method display should be defined as slot and looks like :
Code:
void MainWindow::display()
{
label->setVisible(!label->isVisible());// Set the status of the opposite
QTimer::singleShot(500,
this,
SLOT(display
()));
// call display() after 500 ms }
Re: how to show and hide Qlabel continuously on mainwindow
Quote:
Originally Posted by
Lesiok
Method display should be defined as slot and looks like :
Code:
void MainWindow::display()
{
label->setVisible(!label->isVisible());// Set the status of the opposite
QTimer::singleShot(500,
this,
SLOT(display
()));
// call display() after 500 ms }
Thanks for the reply sir..
I was placed that method...but when i run my program..it is showing that..
"The program has unexpectedly finished."
Thanks in advance..
Re: how to show and hide Qlabel continuously on mainwindow
Run your program in your debugger. When it crashes look at where it crashed in the back trace you will likely be given.