Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Issues with QSettings::value()::toInt()

    General and Desktop
    2
    5
    2157
    Loading More Posts
    • 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.
    • S
      spode last edited by

      Why can not i obtain data i need from this class, though it does not return errors and is similar than the snippet provided by QSettings (editor)?

      @
      #include "programsettings.h"

      #include <QSettings>
      #include <QVariant>
      #include <QDesktopWidget>
      #include <messaggioantipanico.h>
      #include <QDebug>

      ProgramSettings::ProgramSettings()
      {
      }

      int ProgramSettings::getIngrandimento()
      {
      QSettings s("SeiFreud", "Tecnophobie");
      int i = s.value("ingrandimento", QVariant::fromValue(1)).toInt();
      qDebug()<< "ingrandimento corrente: " + i;
      return i;
      }

      void ProgramSettings::setIngrandimento(const int nvalue)
      {
      qDebug()<<"ingrandimento incrementato di uno: " + nvalue;
      if(nvalue > 0 && nvalue < 4)
      {
      QSettings s("SeiFreud", "Tecnophobie");
      s.setValue("ingrandimento", QVariant::fromValue(nvalue));

          emit ingrandimentoChanged(nvalue);
          qDebug()<<"signal";
      }
      else
      {
          MessaggioAntiPanico a("Non è possibile cambiare ulteriormente l' ingrandimento!");
          a.show();
      }
      

      }

      QRect ProgramSettings::getDesktopDims()
      {
      QDesktopWidget * d = new QDesktopWidget();
      return d->screenGeometry(-1);
      }

      QSize ProgramSettings::getDesktopDimsAsQSize()
      {
      QDesktopWidget * d = new QDesktopWidget();
      return QSize(d->width(), d->height());
      }

      int ProgramSettings::getDesktopHeight()
      {
      return ProgramSettings::getDesktopDims().width();
      }

      int ProgramSettings::getDesktopWidth()
      {
      return ProgramSettings::getDesktopDims().height();
      }

      void ProgramSettings::addIngrandimento()
      {
      qDebug()<<"addIngrandimento";
      qDebug()<<"ingrandimento non aggiornato: " + this->getIngrandimento();
      this->setIngrandimento(this->getIngrandimento() + 1);
      }

      void ProgramSettings::reduceIngrandimento()
      {
      this->setIngrandimento(this->getIngrandimento() - 1);
      }
      @

      1 Reply Last reply Reply Quote 0
      • K
        koahnig last edited by

        Can you explain why you are adding the integers to a string as you do in a number of your qDebug() output?

        E.g.
        line 17
        line 23
        line 64

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply Reply Quote 0
        • S
          spode last edited by

          That is right!

          is there no way to cript information of qsettings...or to hide them?

          1 Reply Last reply Reply Quote 0
          • K
            koahnig last edited by

            You did not answer my question.

            What do you expect as output from line 17 ?

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply Reply Quote 0
            • S
              spode last edited by

              Oh. Excuse me. Nothing, becouse i should have written QString::setNum(I).
              In fact it is right! :)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post