Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Weird error: "2 overloads have no legal conversion"
-
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?
-
QWidget::palette() returns a const object. Do it properly:
@
QPalette p = win->palette();
p.setColor(QPalette::Window, Qt::white);
win->setPalette(p);
@
-
D'oh! I'm relatively new to C++ and I forgot that the assignment ("=") makes a copy. Thanks!