[英]error C2664: 'App *const' to 'QWidget *'
I'm trying to put an animated gif into my program. 我正在尝试将动画gif放入程序中。
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 错误C2664:'QLabel :: QLabel(QWidget *,Qt :: WindowFlags)':无法在行上将参数1从'TestApp * const'转换为'QWidget *'
QLabel *processLabel=new QLabel(this);
Any ideas? 有任何想法吗? Thanks!
谢谢!
EDIT: TestApp is a custom class. 编辑:TestApp是一个自定义类。
If TestApp
is a custom class, then it's perfectly normal that this code doesn't work. 如果
TestApp
是自定义类,则此代码不起作用是完全正常的。
Every UI element of Qt may take a parameter at construction, which is the QWidget
that will act as a parent. Qt的每个UI元素在构造时都可以使用一个参数,该参数是将充当父级的
QWidget
。 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
). 您应该在Qt文档(尤其是
QWidget constructor
的文档)中阅读有关此内容的更多信息。
In your case, you shouldn't pass this
to the QLabel constructor. 在你的情况,你不应该通过
this
的QLabel构造函数。 You must pass another widget that'll become this QLabel
parent. 您必须传递另一个将成为该
QLabel
父级的小部件。
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). 它等待
QWidget
,但是得到了您的类(它在任何时候都不继承QWidget
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.