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. Target deletion when animation is finished
Forum Updated to NodeBB v4.3 + New Features

Target deletion when animation is finished

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 6.1k 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.
  • K Offline
    K Offline
    kruvva
    wrote on last edited by
    #1

    Hello Team,

    How do I delete the target object of QProperyAnimation when animation is finished?

    Here is a sample code snippet that I am trying to use.
    @
    label->show();
    QPropertyAnimation *animation = new QPropertyAnimation(this);
    animation->setTargetObject(label);
    animation->setDuration(time);
    animation->setPropertyName("geometry");
    animation->setStartValue(QRect(0, label->height(), label->width(), label->height()));
    animation->setEndValue( QRect(1680, label->height(), label->width(), label->height()));

    connect(animation, signal( finished() ), this, slot( DeleteTarget(label) );

    animation->start(QAbstractAnimation::DeleteWhenStopped);
    @

    As you have noticed I want delete my target object, here label, when the animation is finished. But I realized that I can not pass "label" as a parameter to the slot DeleteTarget().

    So how do I delete the target, the label, after the animation is completed? I don't think I can delete the target after calling animation->start(), as the animation requires it.

    Appreciate your response.

    Rao

    Edit: Added code tags (@) around the code. Please do that yourself next time; Andre

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kkrzewniak
      wrote on last edited by
      #2

      From the top of my head.
      @
      connect(animation,SIGNAL(finished()),this,SLOT(deleteTarget()));
      animation->start();

      void deleteTarget()
      {
      QPropertyAnimation animation = qobject_cast<QPropertyAnimation>(sender());
      if(animation)
      {
      animation->targetObject()->deleteLater();
      animation->deleteLater();
      }
      }
      @

      or
      @
      connect(animation,SIGNAL(finished()),label,SLOT(deleteLater()));
      @

      Me, Grimlock, not "nice dino". ME BASH BRAINS!

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kruvva
        wrote on last edited by
        #3

        Thanks for the response. If I call

        @
        connect(animation,SIGNAL(finished()) ,label, SLOT(deleteLater()));
        @

        When is the label deleted?

        1. Is it when the finished signal is emitted or
        2. later, when the program exits?

        Thanks

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kkrzewniak
          wrote on last edited by
          #4

          From the documentation. Try having a look at it sometimes. :-P

          @
          void QObject::deleteLater () [slot]
          @

          Schedules this object for deletion.
          The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started.

          Me, Grimlock, not "nice dino". ME BASH BRAINS!

          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