Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Can't use variables on WizardPage::nextId(), says they are read-only

[Solved] Can't use variables on WizardPage::nextId(), says they are read-only

Scheduled Pinned Locked Moved General and Desktop
qwizardwizardpagesnextid
7 Posts 2 Posters 2.1k 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.
  • R Offline
    R Offline
    roseicollis
    wrote on last edited by roseicollis
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      nextId is a const function so you can't modify your object inside it

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        nextId is a const function so you can't modify your object inside it

        R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        @SGaist And what option do I have to do what I'm trying to do? (I tried removing the const but then its a caos )

        Thank you!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          First thing to do is identify the flow of your QWizard, why do you need that variable modified in nextId ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          0
          • SGaistS SGaist

            First thing to do is identify the flow of your QWizard, why do you need that variable modified in nextId ?

            R Offline
            R Offline
            roseicollis
            wrote on last edited by
            #5

            @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'

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It's not at all the role of the nextId function rather validatePage

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              R 1 Reply Last reply
              0
              • SGaistS SGaist

                It's not at all the role of the nextId function rather validatePage

                R Offline
                R Offline
                roseicollis
                wrote on last edited by
                #7

                @SGaist Mmm I see... I thought I had to do it on nextId and I was... ¿close-minded? on this way... I see now there is isComplete and validatePage. I'll try there! Thank you!

                1 Reply Last reply
                0

                • Login

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