I have signal/slot code. I want function on another class to work when checkbox is being toggled. I wrote the following code. Signal/Slot is working properly on Debug mode. However, it does not work on Release mode.
I also want my program to works dynamically. I do not need to open a new window.
Here is my code. Thank you in advance.
preferences.cpp
Projects *projects;
// projects = new Projects; // I dont want to create new one. I just want to make changes on the existing Mainwindow (Projects class)
connect(ui->checkBox_toolbar, SIGNAL(toggled(bool)), projects, SLOT(hide_toolbar(bool)));
connect(ui->checkBox_button, SIGNAL(toggled(bool)), projects, SLOT(hide_buttons(bool)));
projects.cpp
void Projects::hide_toolbar(bool checked)
{
ui->toolBar->setVisible(checked);
}
I have got warning: 'projects' may be used uninitialized in this function [-Wmaybe-uninitialized] connect(ui->checkBox_toolbar, SIGNAL(toggled(bool)), projects, SLOT(hide_toolbar(bool)));
And error: "QObject::connect: Cannot connect QCheckBox::toggled(bool) to (null)::hide_toolbar(bool)"
connect(ui->checkBox_toolbar, &QCheckbox::toggled, projects, &Projects::hide_toolbar);- Benjamin T