当我在QtCreator3.3.2中用Qt4.8.6在Ubuntu14.04中编译一个示例代码时,发生了以下错误:
videowidget.cpp:19: error: no match for call to '(QPalette) ()'
palette = palette();
^在这个片段中:
VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent),surface(0)
{
setAutoFillBackground(false);
setAttribute(Qt::WA_NoSystemBackground,true);
setAttribute(Qt::WA_PaintOnScreen,true);
palette = this->palette();//here's the error
palette.setColor(QPalette::Background,Qt::black);
setPalette(palette);
setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
surface = new VideoWidgetSurface(this);
}我在Qt助手和QWidget手册中查找了QWidget类和QWidget类:
存取功能: const QPalette & palette () const void setPalette ( const QPalette &)
在我看来,QWidget有palette()函数,所以VideoWidget肯定会拥有它。但是,这样的错误出现了。提前谢谢。
发布于 2015-04-21 21:07:22
在声明同名变量时,可以隐藏palette()。使用其他名称,例如:
QPalette myPalette = palette();在您的代码片段中,您有另一个使用this的工作解决方案
QPalette palette = this->palette();https://stackoverflow.com/questions/29782835
复制相似问题