jump to navigation

Smooth fade in / out and questions. August 14, 2009

Posted by tumaix in planetkde-tomazcanabrava.
trackback

I just added smooth fade in in my little rocs, and worked like a charm. with one small mistake, well, not mistake.

I now have a memory leak ;D ( trying to fix that )

the fluffy constructor.

QTimeLine *timeLine = new QTimeLine(500, this);
timeLine->setFrameRange(0, 50);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(removeOpacity()));
timeLine->start();

the unfluffy, memleaked, not-working destructor.

NodeItem::~NodeItem(){
QTimeLine *timeLine = new QTimeLine(500, this);
timeLine->setFrameRange(0, 50);
connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(addOpacity()));

timeLine->start();

}

the destructor code doesnt works, because it does not wait for the timeline to finish before finishing the method.

I’v tried with sleep(500), and I got a freeze

tried with QThread::sleep(), my class doesn’t xtends QThread

bleh.

so, actually I have 2 memleaks, because I don’t delete the 2 QTimeLines.

but if I do timeLine->deletelater(), the animation isn’t shown, and the ball will be 100% translucent.

dear lazyweb, can anyone point me to the right direction on how to do this?

and the second, rocs has gained some icons.

not pretty icons, I’m no nuno pinheiro, so I want feedback on my icons too ;)

snapshot3

About these ads

Comments»

1. Ben Boeckel - August 14, 2009

How about this:

connect(timeLine, SIGNAL(finished()), timeLine, SLOT(deleteLater()));

?

2. Chani - August 14, 2009

it’s too late. you’re already in the destructor, which means it’s already half-deleted.

your best bet is to find a way to not have other code delete this object, but have it call some other function like destroy() that does this timer code and then does deleteLater when the timer is done.

3. Wesley - August 14, 2009

I agree with both Ben and Chani. You could use the connect statement from Ben, but call it in another function – not the destructor.

Not sure how it works _exactly_, but I’ve implemented fade-in and fade-out when adding items to a Qt app that is a bit similar to this. While the code is rather ugly and I haven’t worked on it much, it _might_ help. Relevant code:
http://code.google.com/p/qlogic/source/browse/trunk/sceneitem.cpp (initItem and deleteItem functions)

I hope it helps!

4. Esben Mose Hansen - August 15, 2009

Having a destructor that takes 500ms to run would be quite surprising behavior in any case, I’d say.

5. tada - August 15, 2009

Post your icons in a larger size if you want feedback.

6. Larso - August 15, 2009

Your app was freezing when using sleep(500), because it couldn’t update the UI at all while it was stuck in the destructor. The same would have happened with QThread::sleep(). The main event loop and the destructor are run in the same thread. And so your app ends up freezing and after that the QTimeLine will be destroyed and it couldn’t do the animation. Something like that.

And if you just do that deleteLater() call like you said, it’d just end up destroying it as soon as it gets back to the main event loop, where the animation is also run I think. It might actually do one frame of animation before getting destroyed, or not.

Others have already given suggestions.

7. unknowing - August 15, 2009

need more context


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: