Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check if picture is displayed

Check if picture is displayed

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 659 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ShodanS Offline
    ShodanS Offline
    Shodan
    wrote on last edited by
    #1

    Hello.

    I created a window that shows a little animation (gif) when the application starts.
    At the end of the animation, a "end" picture is displayed in the same window using QObject::connect.

        centralAnimLabel = new QLabel(this);
        centralAnim = new QMovie("windowLogs/centralAnim.gif");
        centralAnimLabel->setMovie(centralAnim);
        centralAnimLabel->move(112, 158);
        centralAnim->start();
        QObject::connect(centralAnim, SIGNAL(finished()), this, SLOT(endAnim()));
    

    The "endAnim"SLOT:

    void mainWindow::endAnim()
    {
        endAnimPicture = new QLabel(this);
        endAnimPicture->setPixmap(QPixmap("windowLogs/endCentralAnim.jpg"));
        endAnimPicture->move(225, 158);
        endAnimPicture->show();
    }
    

    A button is there to stop and hide the animation.
    Here is the SLOT the button is connected to:

    void mainWindow::btn3()
    {
        centralAnim->stop();
        centralAnimLabel->hide();
    }
    

    If I click the button before the animation is finished, it stops and hides. The "end" picture does not appear.
    So far all is right.

    Now, the problem is:
    I want the same button to be able to hide the "end" picture once the animation finished.
    Simply adding "endAnimPicture->hide();" to the SLOT of the button seems not to be possible because it crashes the application (no more responding message), if the button is clicked before the end of the animation.
    Quite logic in my opinion, since I tell the program to hide something that not exists yet.

    I tried setting a condition "if picture is displayed"...
    After trying many things that made crash the application, the button's SLOT looks like this:

    void mainWindow::btn3()
    {
        centralAnim->stop();
        centralAnimLabel->hide();
    
        if(!endAnimPicture)
        {
          endAnimPicture->hide();
        }
    }
    

    No more errors or crashes, but the picture does not hide by clicking the button at the end of the animation.

    Is this the right way to go?
    If yes, what is wrong with my condition?

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why are you creating your labels in these functions ? Just create them in your constructor, hide them as needed.

      Currently you have a big memory leak since you create a new endAnimPicture every time endAnim is called.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • ShodanS Offline
        ShodanS Offline
        Shodan
        wrote on last edited by
        #3

        So easy... Shame on me :-)

        At the begining, I tried to create the label in the constructor and assign a picture to it inside the slot.
        What not really worked for me.

        Thank you for that and the memory leak tip!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved