Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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{
        private:
            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 = "";
    	settings->beginGroup(grp);
    	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;
    
    	}
    	
    	sttngs->endGroup();
    	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.

    Regards


Log in to reply