I'm trying to put an animated gif into my program.
However, when I follow the proper syntax
QMovie *hit1=new QMovie("BadExplosion.gif");
QLabel *processLabel=new QLabel(this);
processLabel->setMovie(hit1);
hit1->start();
in the
void TestApp::draw()
{
//this code and other drawing code here
}
I run into the error
error C2664: 'QLabel::QLabel(QWidget *, Qt::WindowFlags)' : Cannot convert parameter 1 from 'TestApp *const' to 'QWidget *' on the line
QLabel *processLabel=new QLabel(this);
Any ideas? Thanks!
EDIT: TestApp is a custom class.
If TestApp
is a custom class, then it's perfectly normal that this code doesn't work.
Every UI element of Qt may take a parameter at construction, which is the QWidget
that will act as a parent. This parent will notably have the responsibility for handling its children deletion. You should read more about this in the Qt Documentation (esp. the doc for QWidget constructor
).
In your case, you shouldn't pass this
to the QLabel constructor. You must pass another widget that'll become this QLabel
parent.
The compiler shows clearly this problem with the message you got. It waits for a QWidget
, but got your class instead (which doesn't inherit QWidget
at any point).