PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 107 - QPropertyAnimation crashes program on setStartValue()
: QPropertyAnimation crashes program on setStartValue()
Status: CLOSED INVALID
Product: PySide
Classification: Unclassified
Component: QtCore
: HEAD
: Other Other
: P5 critical
Assigned To: renato filho
: http://doc.trolltech.com/4.6/animatio...
:
:
  Show dependency treegraph
 
Reported: 2009-12-09 14:50 EET by aspidites
Modified: 2010-03-24 16:11 EET (History)
5 users (show)

See Also:


Attachments
Simple animation example (complete) (406 bytes, text/x-python)
2009-12-10 10:49 EET, Anderson Lizardo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description aspidites 2009-12-09 14:50:03 EET
** Steps to Reproduce**
Given the following C++ code as a guide:

  QPushButton button("Animated Button");
  button.show();

  QPropertyAnimation animation(&button, "geometry");
  animation.setDuration(10000);
  animation.setStartValue(QRect(0, 0, 100, 30));
  animation.setEndValue(QRect(250, 250, 100, 30));

  animation.start();

I wrote the following in Python:

  import sys
  from PySide.QtCore import *
  from PySide.QtGui import *


  app = QApplication(sys.argv)

  button = QPushButton("Animated Button")
  button.show()

  animation = QPropertyAnimation(button, "geometry")
  animation.setDuration(10000)
  animation.setStartValue(QRect(0, 0, 100, 30))
  animation.setEndValue(QRect(250, 250, 100, 30))

  animation.start()

  app.exec_()

** Expected Result**
"This code will move button from the top left corner of the screen to the
position (250, 250) in 10 seconds (10000 milliseconds)." -- Qt Documentation

** Actual Result**
  $ python2.5 simple_animation.py
  Traceback (most recent call last):
    File "simple_animation.py", line 15, in <module>
      animation.setStartValue(QRect(0, 0, 100, 30))
  Boost.Python.ArgumentError: Python argument types in
      QVariantAnimation.setStartValue(QPropertyAnimation, QRect)
  did not match C++ signature:
      setStartValue(QVariantAnimation {lvalue}, QVariant)

As suggested, I tried the following code:

import sys
  from PySide.QtCore import *
  from PySide.QtGui import *


  app = QApplication(sys.argv)

  button = QPushButton("Animated Button")
  button.show()

  animation = QPropertyAnimation(button, "geometry")
  animation.setDuration(10000)
  animation.setStartValue(QVariant("0, 0, 100, 30"))
  animation.setEndValue(QVariant("250, 250, 100, 30"))

  animation.start()

  app.exec_()

Which results in:
  $ python2.5 simple_animation.py
  QPropertyAnimation::updateState: starting an animation without end value

While the program actually runs, no animation can be seen.

** More Potentially Useful Information ** 
I'm running this code on my Nokia N900 with firmware version 1.2009.42-11-002.
I suspect that if QPropertyAnimation is exhibiting the above behavior, other
animation classes will as well.
Comment 1 renato filho 2009-12-09 16:07:27 EET
this message "QPropertyAnimation::updateState: starting an animation without
end value" came from Qt.

This  is happening because of wrong type in property.

You need change this lines:

  animation.setStartValue(QVariant("0, 0, 100, 30"))
  animation.setEndValue(QVariant("250, 250, 100, 30"))

to:

  animation.setStartValue(QVariant(QRect(0, 0, 100, 30)))
  animation.setEndValue(QVariant(QRect(250, 250, 100, 30)))


using QVariant("0, 0, 100, 30") you will create a QVariant whit QString
the correct is use QVariant(QRect(250, 250, 100, 30)).
Comment 2 aspidites 2009-12-09 16:42:54 EET
Strange, When I make the requested changes, I see no errors, but still see no
animation. I will play with it using different properties (as I suspect I am
not seeing anything because of being on a Maemo platform)

Also, why is there the need for QVariants when the original C++ code doesn't
require them?
Comment 3 aspidites 2009-12-09 16:55:29 EET
Never mind, I understand why QVariant is needed now. Still not understanding
why animations are showing as expected, but I'm sure it is not related to
PySide itself.

Thanks renato
Comment 4 aspidites 2009-12-09 17:05:00 EET
Take that  back, Running the following:

import sys
from PySide.QtCore import *
from PySide.QtGui import *


app = QApplication(sys.argv)

button = QPushButton("Animated Button")
button.show()

animation = QPropertyAnimation(button, "text")
animation.setDuration(10000)
animation.setStartValue(QVariant(QRect(0, 0, 100, 30)))
animation.setEndValue(QVariant(QRect(250, 250, 100, 30)))

animation.start()

app.exec_()

yields the following output in my N900:
$ python simple_animation.py
QPropertyAnimation::updateState: starting an animation without end value

However, setEndValue() is clearly used before animation.start().
Comment 5 renato filho 2009-12-10 09:53:21 EET
If you are changing the property text, you need create QVariants compatible
with this property.

In this case you are trying change the property "text", with QRect values, the
correct is QString, you only can change some proprieties with valid values for
this property.


in this case:

animation = QPropertyAnimation(button, "text")
animation.setDuration(10000)
animation.setStartValue(QVariant(QString("start")))
animation.setEndValue(QVariant(QString("end")))
Comment 6 Anderson Lizardo 2009-12-10 10:26:50 EET
(In reply to comment #5)
> If you are changing the property text, you need create QVariants compatible
> with this property.

I believe the reporter made a typo on that last example.

Anyway, I just tried it here locally (adding the missing code for the full C++
example to run, such as a parent for the button), and indeed the C++ example
works, where equivalent Python code does not.

I printed the startValue() and endValue() return values before and after
animation.start(), and looks like on Python the QVariant is being invalidated
for some reason. Make some parenting issue?

I did the same test for C++ and the QVariants returned by startValue() and
endValue() stayed the same before/after animation.start().
Comment 7 Anderson Lizardo 2009-12-10 10:49:12 EET
Created attachment 29 [details]
Simple animation example (complete)

My mistake. I just noticed I pasted exactly the buggy code in comment #4
instead of the correct one.

After fixing the example, it worked exactly as on C++.

I attached my (working) code for reference.
Comment 8 aspidites 2009-12-10 21:47:40 EET
(In reply to comment #6)
> (In reply to comment #5)
> > If you are changing the property text, you need create QVariants compatible
> > with this property.
> 
> I believe the reporter made a typo on that last example.

Right. I was trying to see if maybe I tried to animate a different property I
would get a different answer and never changed that portion of code back.

Thanks for the working code. It does seem to clearly be user error.
Comment 9 renato filho 2009-12-18 14:39:37 EET
this works fine, if you use correct QVariant type as a arg in animation
functions.