我想在QT中为一个简单整数设置动画。为此,我创建了一个int属性,并对其进行了动画处理。我将finished()信号连接到一个插槽,以便在更新时看到我的新值。如果读取我的属性,它总是显示1,但如果我读取附加到属性的整数,则表示udpates。为什么我没有看到我的房产更新?
这是我的代码:
·H
class MaFenetre : public QWidget
{
Q_OBJECT
public:
MaFenetre();
int getToBeAnimated();
void setToBeAnimated(int);
private slots:
void valueChanged(QVariant);
private:
int _toBeAnimated;
Q_PROPERTY(int toBeAnimated READ getToBeAnimated WRITE setToBeAnimated)
};
#endif // MAFENETRE_H
的.cpp
MaFenetre::MaFenetre() : QWidget()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "toBeAnimated");
animation->setDuration(10000);
animation->setStartValue(0);
animation->setEndValue(100);
animation->start();
connect(animation, SIGNAL(valueChanged(QVariant)), this, SLOT(valueChanged(QVariant)));
}
void MaFenetre::valueChanged(QVariant state){
/////////////////////////////
//////THIS DOESN'T WORK////// <-- WHY DOESN'T IT WORK ?
/////////////////////////////
int newValue = property("toBeAnimated").convert(QVariant::Int);
/////////////////////////////
//////THIS WORKS//////
/////////////////////////////
//int newValue = _toBeAnimated;
//Shows the value of newValue
qDebug(QString::number(newValue).toStdString().c_str());
}
int MaFenetre::getToBeAnimated(){
return _toBeAnimated;
}
void MaFenetre::setToBeAnimated(int value){
_toBeAnimated = value;
}