2

I am trying to save the following modification : to enable the pushButton_4.

void Vessels::SaveSettings()
{
    QSettings setting("My_vessels","My_selected_vessels");
    setting.beginGroup("Vessels");
    setting.setValue("selected",ui->pushButton_4->setEnabled(false));
    setting.endGroup();
}

When I run, I get this error: vessels.cpp:838:33: error: reference to type 'const QVariant' could not bind to an rvalue of type 'void' qsettings.h:167:55: note: passing argument to parameter 'value' here

All what I wanna know, is how to setvalue for an object from this window. I mean enabling the button is just an example.

  • This is probably unrelated, but note the extra parentheses around `("My_vessels","My_selected_vessels")`. This expression will evaluate to simply `"My_selected_vessels"` due to the comma operator. – alter_igel Jan 22 '20 at 16:21
  • 1
    "I get this error: vessels.cpp:838:33" I can be wrong but code snipped you show does not have 838 lines. Should we use telepathy to guess which line produces the error? – Slava Jan 22 '20 at 16:36

1 Answers1

3
setting.setValue("selected",ui->pushButton_4->setEnabled(false));

QWidget::setEnabled returns void, which you can't convert to a QVariant in QSettings::setValue. Did you mean ui->pushButton_4->isEnabled()?

dydil
  • 949
  • 7
  • 20
  • I understand what you mean but I want to disable the pushButton_4. What should I do in this case if I cannot use setEnabled(false) ? – Malek Samet Jan 22 '20 at 17:00
  • 2
    You can't do that in one call: you first have to disable it and then save that it is disabled. – dydil Jan 22 '20 at 17:07
  • 1
    `ui->pushButton_4->setEnabled(true/false)` then `setting.setValue("selected", ui->pushButton_4->isEnabled())` – dydil Jan 23 '20 at 10:14
  • OK thank you I did itand it works. After closing the window with saving the parameters, I want to re-open this window by clicking on "open" button in the mainwindow, this button has to open that window and load the saved parameters, how can I do that please ? The problem is that the button that saves the modifications and the one which load them are not on the same window. I need your help please! – Malek Samet Jan 23 '20 at 10:29
  • If you have a different problem, you can close this question and open a new one. – dydil Jan 23 '20 at 10:59