Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: passing ‘const QSettings’ as ‘this’ argument discards qualifiers

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

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by
    #1

    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!

    aha_1980A 1 Reply Last reply
    0
    • cerrC cerr

      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!

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Qt has to stay free or it will die.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved