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

Runtime error



  • I recently changed the initialization of a member variable. Originally, the header had no constructor so I declared the variable on the fly in the declaration:

    private:
    bool m_progressWizardBool = false;
    

    no error here but then I went back later and created a constructor and declared it as such:

    public:
        SettingsPresenter()
        : m_progressWizardBool(false)
        {
    
        }
    ...
    private:
         bool m_progressWizardBool;
    

    after doing that I am now getting a runtime error:

    runtime error: load of value 190, which is not a valid value for type 'bool'
    

    any idea what I have done wrong? It might be helpful to know that the bool is being used in the QML like so:

    if(!settingValue.settingInvalid)
          {
            if(presentationManager.settingsPresenter.getProgressWizardBool() === false)
            {
              presentationManager.settingsPresenter.setProgressWizardBool(1)
            }
    ...
    

    where getProgressWizardBool() and setProgressWizardBool() are declared in the .cpp file for the header in question:

    void SettingsPresenter::setProgressWizardBool(int requestedValue)
    {
        if (m_progressWizardBool != requestedValue)
        {
          m_progressWizardBool = requestedValue;
          emit progressWizardBoolChanged();
        }
    }
    
    bool SettingsPresenter::getProgressWizardBool() const
    {
        return m_progressWizardBool;
    }
    

  • Lifetime Qt Champion

    Hi,

    Why are you passing an int to change the value of a boolean ?

    Can you post the complete code of your class ?



  • @SGaist I posted something incorrectly in my first post. The error is actually coming from the .cpp file:

    SettingsPresenter.cpp:527:12: runtime error: load of value 190, which is not a valid value for type 'bool'
    SettingsPresenter.cpp:518:9: runtime error: load of value 190, which is not a valid value for type 'bool'
    

    I changed the argument to be of type bool as you suggested but the error persists.

    line 527: return m_progressWizardBool;
    line 518: if (m_progressWizardBool != requestedValue)
    

  • Lifetime Qt Champion

    @Circuits said in Runtime error:

    presentationManager.settingsPresenter.setProgressWizardBool(1)

    You are still passing an integer and not a boolean.



  • @SGaist OH sorry I should have mentioned, I changed that as well.



  • I understand now, the mistake I made. I should have defined in the header:

    public:
        SettingsPresenter();
    ...
    private:
    m_progressWizardBool;
    

    and then in the .cpp file:

    SettingsPresenter::SettingsPresenter()
      : m_progressWizardBool(false)
    

Log in to reply