[Solved] Can't use variables on WizardPage::nextId(), says they are read-only
-
Hi,
I'm doing a QWizard app and I have a wizardpage (named PageWithData) with some line edits. What I want is that if the user press NextButton, and there is any lineedit empty or with an invalid data, the nextID is the same page but with those lineedits in red. I have done it this way and it works fine BUT when the user enters the first time, the lineedits are already in red and I want them to be in white until the user presses the NextButton.
int PageWithData::nextId() const { if (ValidateLineEditsInfo()) return BaseWizard::NextPage; // <-- this works fine else { if (!ValidateFirstLineEdit) { FirstLineEdit->setStyleSheet("QLineEdit{background-color: #ffcccc;}"); FirstLineEdit->setFocus(); }else{ FirstLineEdit->setStyleSheet("QLineEdit{background-color: white;}"); } if (!ValidateSecondLineEdit) { SecondLineEdit->setStyleSheet("QLineEdit{background-color: #ffcccc; }"); SecondLineEdit->setFocus(); }else{ SecondLineEdit->setStyleSheet("QLineEdit{background-color: white; }"); } } }
I've tried to do the next:
- declared a bool VarTest on the .h . Then on the constructor VarTest = false; and then :
int WP1111::nextId() const { if(VarTest) { if (ValidateLineEditsInfo()) return BaseWizard::NextPage; // <-- this works fine else { if (!ValidateFirstLineEdit) { FirstLineEdit->setStyleSheet("QLineEdit{background-color: #ffcccc;}"); FirstLineEdit->setFocus(); }else{ FirstLineEdit->setStyleSheet("QLineEdit{background-color: white;}"); } if (!ValidateSecondLineEdit) { SecondLineEdit->setStyleSheet("QLineEdit{background-color: #ffcccc; }"); SecondLineEdit->setFocus(); }else{ SecondLineEdit->setStyleSheet("QLineEdit{background-color: white; }"); } } } VarTest= true; }
But it gaves me this error (Where I put: VarTest= true; ):
error: assignment of member 'PageWithData::VarTest' in read-only object
And I don't know how should I do it. What do I do bad or which would be the best way of doing it...
I thought about getting the nextbutton click event but my program crashes if I put this in the constructor and I can't see why, I know that the problem is in the part of QWizard::NextButton), SIGNAL(clicked()) but I see it well...
connect(wizard()->button(QWizard::NextButton), SIGNAL(clicked()), this, SLOT(CheckFields()));
Thank yo so much!
-
Hi,
nextId is a const function so you can't modify your object inside it
-
First thing to do is identify the flow of your QWizard, why do you need that variable modified in nextId ?
-
@SGaist Well what I want is to have the line edits with the white background at first and then, when the user presses the NextButton if there is any lineedit empty, put its background in red and the focus on it to remark that there is some information bad or missing.
To do that I thought that I could do it in the nextId function... maybe here is the mainly mistake. If it is I'll apreciate so much if you tell me how can I do it better and where.
The problem is that when I get to this wizardpage, it goes to ::initializepage(), then ::nextId() twice .... so when the page appears to the user, it already compared the information inside the lineedits (which are empty until the user writes on them of course) and put it in red (and I remember that when it appears I want them in white). To get what I want, I tried to put a control variable or something like this but any change on it makes that mistake I have because of the 'const'
-
It's not at all the role of the nextId function rather validatePage