i want animate qt widget qtimer (without animation system) , painting,so put timer , starting point in enterevent , in timercall slot make border bigger , on... doesn't run , application exit code 255:
.h
#include <qtwidgets> class qwidget; class qpainter; class qtimer; class sample : public qwidget { q_object public: sample(qwidget *parent = 0); ~sample(); private: qtimer *timer; int weight=1, step=1; protected: virtual void paintevent(qpaintevent *); virtual void enterevent(qevent *); public slots: void timercall(); };
.cpp
sample::sample(qwidget *parent) : qwidget(parent) { connect(timer,signal(timeout()),this,slot(timercall())); } sample::~sample() {} void sample::paintevent(qpaintevent * ) { qpainter painter(this); painter.setpen(qpen(qt::black,weight)); painter.setrenderhint(qpainter::antialiasing); qrect rectangle=qrect (10,10,width()-20,height()-20); painter.drawrect(rectangle); } void sample::enterevent(qevent *) { timer->start(100); } void sample::timercall() { weight+=1; if (step > 10) { timer->stop(); } step++; repaint(); }
and when remove line code:
connect(timer,signal(timeout()),this,slot(timercall()));
in enterevent application crash happened.
private: qtimer *timer;
you never create object referenced timer
pointer.
declare qtimer timer
instead, it's internal object there's no need use pointer.
Comments
Post a Comment