Getter not working
-
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? -
@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 insideslots
? 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.