Weird error: "2 overloads have no legal conversion"
General and Desktop
3
Posts
2
Posters
6.2k
Views
1
Watching
-
wrote on 28 Feb 2011, 15:29 last edited by
I have some code that is setting a color in a QMainWindows palette. It works fine if I have:
@
QPalette p = win->palette();
p.setColor(QPalette::Window, Qt::white);
@But it throws the error "QPalette::setColor 2 overloads have no legal conversion for 'this' pointer" if I have this:
@
(win->palette()).setColor(QPalette::Window, Qt::white);
@Can anyone explain this error to me?
-
wrote on 28 Feb 2011, 15:34 last edited by
QWidget::palette() returns a const object. Do it properly:
@
QPalette p = win->palette();
p.setColor(QPalette::Window, Qt::white);
win->setPalette(p);
@ -
wrote on 28 Feb 2011, 15:38 last edited by
D'oh! I'm relatively new to C++ and I forgot that the assignment ("=") makes a copy. Thanks!
1/3