Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Getter not working

Getter not working

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 264 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by Circuits
    #1

    Alright my getter doesn't seem to work:

    In the .cpp:

    //setter
    void SettingsPresenter::setWizardBool(int requestedValue)
    {
        if (m_wizardBool == requestedValue)
            return;
    
        m_wizardBool = requestedValue;
        emit wizardBoolChanged();
        std::cout << "setWizardbool called value is: " << m_wizardBool << "\n";
    }
    
    //getter
    bool SettingsPresenter::getWizardBool() const
    {
        std::cout << "getWizardbool called value is: " << m_wizardBool << "\n";
        return m_wizardBool;
    }
    

    in the .h:

       void setWizardBool(int requestedValue);
       int  getWizardBool() const;
    
    signals:
       void wizardBoolChanged();
    
    private:
       bool m_wizardBool = false;
    

    I am calling the function from the QML `WizardPopupNumericKeyboard.qml' like so:

    case 0:
          control.destroy()
          break;
        case 1:
          settingValue.value=Number(outValue)
          //user has clicked "finish" on numberpad so set bool too true
          presentationManager.settingsPresenter.setWizardBool(1)
    ...
    

    from the QML file where where the keyboard component is being instantiated I have setup a connection:

          Connections
          {
            target: presentationManager.settingsPresenter
            onWizardBoolChanged:
            {
              //errors out on this line
              if(presentationManager.settingPresenter.getWizardBool() === true)
              {
                //progess wizard
                allowNext = true
                //set value back to false
                presentationManager.settingsPresenter.setWizardBool(0)
              }
              return
            }
          }
    

    error is:

    TypeError: Cannot read property 'getWizardBool' of undefined
    setWizardbool called value is: 1
    

    A) Not sure why I am getting a TypeError
    B) Why is the the TypeError showing up before the print statement coming from the setter? Shouldn't that print statement show up first?

    sierdzioS 1 Reply Last reply
    0
    • C Circuits

      Alright my getter doesn't seem to work:

      In the .cpp:

      //setter
      void SettingsPresenter::setWizardBool(int requestedValue)
      {
          if (m_wizardBool == requestedValue)
              return;
      
          m_wizardBool = requestedValue;
          emit wizardBoolChanged();
          std::cout << "setWizardbool called value is: " << m_wizardBool << "\n";
      }
      
      //getter
      bool SettingsPresenter::getWizardBool() const
      {
          std::cout << "getWizardbool called value is: " << m_wizardBool << "\n";
          return m_wizardBool;
      }
      

      in the .h:

         void setWizardBool(int requestedValue);
         int  getWizardBool() const;
      
      signals:
         void wizardBoolChanged();
      
      private:
         bool m_wizardBool = false;
      

      I am calling the function from the QML `WizardPopupNumericKeyboard.qml' like so:

      case 0:
            control.destroy()
            break;
          case 1:
            settingValue.value=Number(outValue)
            //user has clicked "finish" on numberpad so set bool too true
            presentationManager.settingsPresenter.setWizardBool(1)
      ...
      

      from the QML file where where the keyboard component is being instantiated I have setup a connection:

            Connections
            {
              target: presentationManager.settingsPresenter
              onWizardBoolChanged:
              {
                //errors out on this line
                if(presentationManager.settingPresenter.getWizardBool() === true)
                {
                  //progess wizard
                  allowNext = true
                  //set value back to false
                  presentationManager.settingsPresenter.setWizardBool(0)
                }
                return
              }
            }
      

      error is:

      TypeError: Cannot read property 'getWizardBool' of undefined
      setWizardbool called value is: 1
      

      A) Not sure why I am getting a TypeError
      B) Why is the the TypeError showing up before the print statement coming from the setter? Shouldn't that print statement show up first?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Circuits said in Getter not working:

      A) Not sure why I am getting a TypeError

      Because settingPresenter object is not defined (it's null). You need to check your code to make sure it's set.

      Also - is getWizardBool() defined as Q_INVOKABLE or inside slots? Otherwise QML won't see it.

      B) Why is the the TypeError showing up before the print statement coming from the setter? Shouldn't that print statement show up first?

      You are printing the message after you emit the signal. So it is printed after the slot is called.

      (Z(:^

      1 Reply Last reply
      1

      • Login

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