Results 1 to 6 of 6

Thread: how to show and hide Qlabel continuously on mainwindow

  1. #1
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. label=ui->label;
    7.  
    8. display();
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::display()
    17. {
    18. while(1)
    19. {
    20. label->show();
    21. sleep(1000);
    22. label->hide();
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    when i run the program mainwindow is not comming...and no errors are comming..
    Please help me..
    Thank you.
    Last edited by anda_skoa; 30th March 2014 at 12:06. Reason: Changed [quote] to [code] tags

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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..

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to show and hide Qlabel continuously on mainwindow

    Method display should be defined as slot and looks like :
    Qt Code:
    1. void MainWindow::display()
    2. {
    3. label->setVisible(!label->isVisible());// Set the status of the opposite
    4. QTimer::singleShot(500,this,SLOT(display()));// call display() after 500 ms
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to show and hide Qlabel continuously on mainwindow

    Quote Originally Posted by Lesiok View Post
    Method display should be defined as slot and looks like :
    Qt Code:
    1. void MainWindow::display()
    2. {
    3. label->setVisible(!label->isVisible());// Set the status of the opposite
    4. QTimer::singleShot(500,this,SLOT(display()));// call display() after 500 ms
    5. }
    To copy to clipboard, switch view to plain text mode 
    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..

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.

Similar Threads

  1. Replies: 22
    Last Post: 26th November 2015, 20:27
  2. mouseMoveEvent show/hide
    By davidovv in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2013, 09:50
  3. Show and hide Tab page
    By fulin in forum Newbie
    Replies: 3
    Last Post: 28th March 2012, 09:43
  4. Hide and Show QMenu
    By febil in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2009, 09:31
  5. How to hide mainwindow at program start up
    By palmer in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2008, 14:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.