PDA

View Full Version : Give const QSettings& from one to other class



atomic
11th April 2014, 15:55
Hi all,

in my MainWindow class i used QSettigns in order to set (save / load) some options who are connected with GUI. MainWindow class contain also Utility class who need few value from QSettings and now i make it like this

my MainWindow class


class MainWindow
{
public:
// rest methods
void loadSettings();

private:
QSettings settings;
Utility utility;
};

void MainWindow::loadSettings()
{
// here i load settings from .ini file
}


and method from Utility class


void Utility::getSettings( const QSettings & settings )
{
// here i take some values from QSettings
}


Now my question - is it a good solution to give some settings to other class?
Maybe are contraindication?

Thanks ;)

anda_skoa
11th April 2014, 16:44
Looks good to me.

Cheers,
_

atomic
12th April 2014, 08:49
Problems are started when i try read from const QSettings because i cant use beginGroup() and i must write all path to get value.
For example i must write


void Utility::getSettings( const QSettings & settings )
{
// --------

for( QVariant & ext : settings.value( "Advanced/selectedTypes/Files" ).toList() )
std::cout<< ext.toString().toStdString() <<std::endl;
}

to read few value with qlist as key.
Meybe i should to give not constant QSettings to Utility class?

anda_skoa
12th April 2014, 10:53
Meybe i should to give not constant QSettings to Utility class?

That or create a local QSettings object.

Cheers,
_