Qt6 topics merged with General

error: passing ‘const QSettings’ as ‘this’ argument discards qualifiers

  • Hi,

    I seem not to be able to resolve the foillowing error:
    error: passing ‘const QSettings’ as ‘this’ argument discards qualifiers

    I've got the following:

    class scaper :QMainWindow{
            QString CmdStrBuild(const QSettings *settings, const QString &grp) const;
            const QSettings *sttngs
    int scaper::ToolCmdExec() {
    	int rv = OK;
    	QStringList cmdlist;
    	QStringList groups = sttngs->childGroups();
    	foreach (const QString &grp, groups) {
    	dbg_prnt << "grp: " << grp.toStdString() << std::endl;
    	   cmdlist << CmdStrBuild(sttngs,grp);
    	foreach (const QString &cmd, cmdlist) {
    	dbg_prnt << "cmd: " << cmd.toStdString();
    	return rv;
    QString scaper::CmdStrBuild(const QSettings *settings, const QString &grp) const {
    	QString cmd = "";
    	optnslst = new QListWidget(this);
    	foreach(const QString &key, sttngs->childKeys()) {
    		item = new QListWidgetItem(optnslst);
    		if(sttngs->value(key).toInt()) {
    			dbg_prnt << key.toStdString() << " is checked" <<std::endl;
    			cmd +=" " +key;
    	return cmd;

    The compiler points at this line settings->beginGroup(grp); Is the soilution to reimplement beginGroup() as const or am I misunderstanding this altogether?

    Thanks for any help!

  • Lifetime Qt Champion

    hi @cerr,

    you are in a const member function and therefore cannot change member variables. From the given context, I guess thats whats happens.


Log in to reply