C++ 来自Qt的奇异错误

C++ 来自Qt的奇异错误,c++,qt,C++,Qt,在Qt编辑器中执行此代码: QPushButton button("Animated Button"); button.show(); QPropertyAnimation animation(&button, "geometry"); animation.setDuration(3000); animation.setStartValue(QRect(0, 0, 100, 30)); animation.setEndValue(QRect(250, 250, 100, 3

在Qt编辑器中执行此代码:

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

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

 animation.setEasingCurve(QEasingCurve::OutBounce);

 animation.start();
我得到一个弹出的错误消息:


您应该始终在堆上创建QWidget,否则您确实会遇到各种错误:

QPushButton* button = new QPushButton("Animated Button");

用VisualStudio调试器钩住它?我甚至没有注意到这是代码的一部分,因为他格式化不正确。好catch@Laurent谢谢你的帮助,这段该死的代码是从中提取的,所以我没想到他们会把这么简单的事情搞砸。事实上,这不是一个好的教程。最有可能发生的情况是,当按钮超出范围时会被删除,但是动画可能仍在引用它,并且最终会出现运行时错误。这很奇怪,因为对象以与声明相反的顺序超出范围,因此动画将在按钮之前超出范围。因此,它不可能仍然引用它。您可以在堆栈上创建小部件。最好不要这样做,但我在这样做的时候从来没有经历过“各种各样的错误”。