Thanks to the Mole for trying to help with my previous post, but the problem remains.
I'm just trying to set the window color and save it so I can restore it on startup, and it's not working. When I try to get the color to save it to the database, the color is empty or invalid.
Here's the code:
void MainWindow::setColors() {
settings.setValue("MainWindow/Color", color);
}
void MainWindow::setColors() {
QColor color = QColorDialog::getColor();
QPalette palette = QPalette(color);
QApplication::setPalette(palette);
QSettings settings(this);
settings.setValue("MainWindow/Color", color);
}
To copy to clipboard, switch view to plain text mode
void MainWindow::saveLook() {
QString color
= settings.
value("MainWindow/Color").
toString();
// tried .value<QColor>() and it didn't work either QFont font
= settings.
value("MainWindow/Font").
value<QFont>
();
qDebug() << "save color will be " << color;
qDebug() << "save font will be " << font;
query.prepare("UPDATE settings set color =?, font =? where id=1");
query.addBindValue(color);
query.addBindValue(font);
query.exec();
qDebug() << "saving look " << query.lastError();
}
void MainWindow::saveLook() {
QSettings settings(this);
QString color = settings.value("MainWindow/Color").toString(); // tried .value<QColor>() and it didn't work either
QFont font = settings.value("MainWindow/Font").value<QFont>();
qDebug() << "save color will be " << color;
qDebug() << "save font will be " << font;
QSqlDatabase db = QSqlDatabase::database(ctrlConn);
QSqlQuery query(db);
query.prepare("UPDATE settings set color =?, font =? where id=1");
query.addBindValue(color);
query.addBindValue(font);
query.exec();
qDebug() << "saving look " << query.lastError();
}
To copy to clipboard, switch view to plain text mode
The problem is (just for Wysota
) qDebug() save color is empty.
If I use .value<QColor>() instead of .toString(), the qDebug() says the color is invalid.
I just want to save the user chosen color to my database and restore it on start up.
Any ideas?
Bookmarks