Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2607

Undocumented behavior of QWizardPage.registerField and QWizardPage.setField

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 6.6.2
    • PySide, Shiboken
    • None

    Description

      Say, I'm a bad guy who doesn't read the docs. I came up with the following code:

      import sys
      
      from PySide6.QtWidgets import QApplication, QWidget, QWizard, QWizardPage
      
      
      class WizardPage1(QWizardPage):
          def __init__(self, parent: QWidget | None = None) -> None:
              super().__init__(parent)
              self.registerField("fieldName", self)
      
          def someFunction(self) -> None:
              # QWizard::setField: Couldn't write to property ''
              self.setField("fieldName", "Guido")
              print("field set from", self.__class__.__name__)
      
      
      class WizardPage2(QWizardPage):
          def __init__(self, parent: QWidget | None = None) -> None:
              super().__init__(parent)
      
          def someFunction(self) -> None:
              print(self.field("fieldName"), "read from", self.__class__.__name__)
      
      
      class Wizard(QWizard):
          def __init__(self, parent: QWidget | None = None) -> None:
              super().__init__(parent)
      
              wp1 = WizardPage1(self)
              self.addPage(wp1)
              wp1.someFunction()
      
              wp2 = WizardPage2(self)
              self.addPage(wp2)
              wp2.someFunction()
      
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
          w = Wizard()
          # w.exec()  # to see that it still works
          app.exit(0)
      

      Here, I register a field without specifying a property. The widget is not in the list of the known ones, therefore the code should fail with a TypeError or something like that.

      So, why doesn't it?

      Instead, I get

      QWizard::setField: Couldn't write to property ''

      in the stderr, and still, the data is passed between the pages.

      So, why to warn, then?

      Instead, I can pass a name of a non-existing property:

      self.registerField("fieldName", self, "nonExistingProperty")
      

      This time, I get a slightly different stderr, but the data appear to pass between pages, too.

      QWizard::setField: Couldn't write to property 'nonExistingProperty'

      So, where are the data stored to?

      I can even enter an illegal property name:

      self.registerField("fieldName", self, "a badly named property")
      

      But, despite the warning, the data is here. According to what stderr shows this time, the property name is unchanged:

      QWizard::setField: Couldn't write to property 'a badly named property'

      So, does QWizard.setField ever fail?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            stsav012 Anton Yablokov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes