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. QSequentialAnimationGroup and destruction of component Animations
Forum Updated to NodeBB v4.3 + New Features

QSequentialAnimationGroup and destruction of component Animations

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 256 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by vikramg
    #1

    I struggled for several hours to trace the source of a
    *** Error in `MyApp': free(): invalid pointer: 0x6e802e6c ***
    segfault I was running into at the exit of my app. I had taken care to use modern RAII idioms, so there should not have been any naked new/deletes. I finally traced the problem to the following:

    I have in my code:

    class MyClass
    {
        . . . 
    private:
        QVariantAnimation A, B;
        QSequentialAnimationGroup AB;
    };
    

    In the constructor I set up the animations A and B, and add them to the SeqAnimGroup:

    AB.addAnimation(&A);
    AB.addAnimation(&B);
    

    I had assumed that the default destructor of MyClass could destroy all component animations. It turned out that the segfault was on the A object. Evidently it was being deleted twice. It was then that I read in the documentation, to my astonishment, that the QSeqAnimGroup destructor also destroys its component animations!

    Why is this!?? QSeqAnimGroup ought to destroy its components only if it has assumed ownership of them! We are not std::moveing the component animations into the SeqAnimGroup (nor am I sure if C++ class member objects can be moved at all). The SeqAnimGroup only takes pointers to its components. In every case where one might imagine this would be used, the component animations will have been created somewhere else, and will be naturally destroyed when they go out of scope. It seems wholly unnecessary for the SeqAnimGroup to destroy them in its own destructor.

    The solution is to call removeAnimation() on the SeqAnimGroup before it gets destroyed, but this should at least have been stated in bold red in the documentation. Am I missing something here? Are there other similar cases elsewhere in the libraries to be aware of?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I would say - RTM

      Adds animation to this group. This will call insertAnimation with index equals to animationCount().
      Note: The group takes ownership of the animation.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • vikramgV Offline
        vikramgV Offline
        vikramg
        wrote on last edited by
        #3

        @Christian-Ehrlicher Ah, thanks for pointing it out, I hadn't noticed that either. I agree, RTM is the final word and I'll mark this solved, but I'm still grumbling about the design philosophy behind such a choice. :)

        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