Skip to content

TypeError: QStackedWidget parent unexpected type 'QMainWindow' #82

Closed

Description

@Magicrafter13
Traceback (most recent call last):
  File "/opt/NSO-RPC/app.py", line 736, in <module>
    window.setupUi(MainWindow)
  File "/opt/NSO-RPC/layout/qt6_layout.py", line 16, in setupUi
    self.stackedWidget = QtWidgets.QStackedWidget(parent=MainWindow)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'QMainWindow'

Activity

  1. MCMi460 commented on Jun 8, 2023

    @MCMi460
    Owner

    I believe that I had this problem as well. I think that uninstalling PyQt5 and reinstalling PyQt6 solved it? Please tell me if that doesn't work, but I think it has something to do with accidentally using PyQt5 when PyQt6 is installed (program checks if PyQt6 is installed, not if it is being used primarily).

  2. Magicrafter13 commented on Jun 9, 2023

    @Magicrafter13
    Author

    I cannot easily do that, as it breaks dependencies I have from other installed packages. Is there some way I can force it (make sure) to use PyQt6 when running this?

  3. MCMi460 commented on Jun 9, 2023

    @MCMi460
    Owner

    Perhaps try a virtual environment? That way you can run an array of packages that are separate from your universal ones.
    If you have python3-venv, just run python3 -m venv venv (from OS to OS, the exact commands may vary).

  4. HotaruBlaze commented on Jun 9, 2023

    @HotaruBlaze
    Contributor
    Traceback (most recent call last):
      File "/opt/NSO-RPC/app.py", line 736, in <module>
        window.setupUi(MainWindow)
      File "/opt/NSO-RPC/layout/qt6_layout.py", line 16, in setupUi
        self.stackedWidget = QtWidgets.QStackedWidget(parent=MainWindow)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'QMainWindow'
    

    Hi, I've only now saw this, if you do pip install pyqt5 it should fix this.

    pyqt6 is installed by default but u can have both pyqt5 and pyqt6 installed by default, and it should default do pyqt5 if both are installed.

    You can also do pip uninstall pyqt6 if your system isn't pyqt6 compatible

    Note: qtpy will try and use pyqt5 by default, then attempts to use pyqt6 afterwards

  5. HotaruBlaze commented on Jun 9, 2023

    @HotaruBlaze
    Contributor
  6. Magicrafter13 commented on Jun 9, 2023

    @Magicrafter13
    Author
    Traceback (most recent call last):
      File "/opt/NSO-RPC/app.py", line 736, in <module>
        window.setupUi(MainWindow)
      File "/opt/NSO-RPC/layout/qt6_layout.py", line 16, in setupUi
        self.stackedWidget = QtWidgets.QStackedWidget(parent=MainWindow)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'QMainWindow'
    

    Hi, I've only now saw this, if you do pip install pyqt5 it should fix this.

    pyqt6 is installed by default but u can have both pyqt5 and pyqt6 installed by default, and it should default do pyqt5 if both are installed.

    You can also do pip uninstall pyqt6 if your system isn't pyqt6 compatible

    Note: qtpy will try and use pyqt5 by default, then attempts to use pyqt6 afterwards

    I already have both pyqt5 and pyqt6 installed, but via my package manager, not pip.

  7. Magicrafter13 commented on Jun 9, 2023

    @Magicrafter13
    Author

    Perhaps try a virtual environment? That way you can run an array of packages that are separate from your universal ones. If you have python3-venv, just run python3 -m venv venv (from OS to OS, the exact commands may vary).

    When trying a virtual environment with the following packages installed via pip: pyqt6, qtpy, requests, qtwidgets, pyside2, pypresence
    I get this output:

    Traceback (most recent call last):
      File "/opt/NSO-RPC/app.py", line 736, in <module>
        window.setupUi(MainWindow)
      File "/opt/NSO-RPC/layout/qt6_layout.py", line 16, in setupUi
        self.stackedWidget = QtWidgets.QStackedWidget(parent=MainWindow)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'PySide2.QtWidgets.QMainWindow'
    

    If I change that from pyqt6 to pyqt5 it appears to work however, so it seems pyqt6 is the bad package, not pyqt5.

    So I guess the end goal is to either make the script use PyQt6 compatible code, or figure out how to force it to use the desired version and not just the latest installed version (probably a Python default?).

    While it's nice to have a workaround, I don't really want to have to use a venv every time I run this 😅.

  8. HotaruBlaze commented on Jun 9, 2023

    @HotaruBlaze
    Contributor

    Perhaps try a virtual environment? That way you can run an array of packages that are separate from your universal ones. If you have python3-venv, just run python3 -m venv venv (from OS to OS, the exact commands may vary).

    When trying a virtual environment with the following packages installed via pip: pyqt6, qtpy, requests, qtwidgets, pyside2, pypresence I get this output:

    Traceback (most recent call last):
      File "/opt/NSO-RPC/app.py", line 736, in <module>
        window.setupUi(MainWindow)
      File "/opt/NSO-RPC/layout/qt6_layout.py", line 16, in setupUi
        self.stackedWidget = QtWidgets.QStackedWidget(parent=MainWindow)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'PySide2.QtWidgets.QMainWindow'
    

    If I change that from pyqt6 to pyqt5 it appears to work however, so it seems pyqt6 is the bad package, not pyqt5.

    So I guess the end goal is to either make the script use PyQt6 compatible code, or figure out how to force it to use the desired version and not just the latest installed version (probably a Python default?).

    While it's nice to have a workaround, I don't really want to have to use a venv every time I run this 😅.

    You shouldn't have pyside2 installed ,that package was never tested or accounted for. doubt its an issue though, you also shouldn't need to use a venv.

    The step that I'm confused about is that the linux install script installed python3-pyqt6 here, in your case, if you already have python3-pyqt5 installed, it should naturally fallback onto python3-pyqt5.

    If you have both installed, try doing the following instead QT_API="pyqt5" /opt/NSO-RPC/app.py and see if it successfully loads that way.

  9. HotaruBlaze commented on Jun 23, 2023

    @HotaruBlaze
    Contributor

    Update about this issue, Another user on the discord encountered this error and we were able diagnose it to being an issue with client/layout/init.py

    Specifically their was an edgecase where both Qt5 and Qt6 are installed, however when trying to fallback to Qt5, it'd still continue to try and load Qt5 layout with Qt6.

    This would either cause it trying to load PySide2, Giving the user something like
    TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'PySide2.QtWidgets.QMainWindow''

    or attempting to load Qt6's layout with Qt5, Giving the following error
    TypeError: QStackedWidget(parent: typing.Optional[QWidget] = None): argument 'parent' has unexpected type 'QMainWindow'

    I've already made a replacement that gets around this issue, and it should be coming to NSO-RPC's development branch and merged into main after some other small bugs are worked out first.

  10. Magicrafter13 commented on Jun 24, 2023

    @Magicrafter13
    Author

    You shouldn't have pyside2 installed ,that package was never tested or accounted for. doubt its an issue though, you also shouldn't need to use a venv.

    Everything I installed in the venv was just based on running the script and every time it failed to run for a missing dependency I installed it. And I did have to use the venv since I can't uninstall pyqt5 or pyqt6 ;)

  11. HotaruBlaze commented on Jun 24, 2023

    @HotaruBlaze
    Contributor

    You shouldn't have pyside2 installed ,that package was never tested or accounted for. doubt its an issue though, you also shouldn't need to use a venv.

    Everything I installed in the venv was just based on running the script and every time it failed to run for a missing dependency I installed it. And I did have to use the venv since I can't uninstall pyqt5 or pyqt6 ;)

    If you want a quick fix without waiting, Apply this commit by editing client/layout/__init__.py and replace it.
    HotaruBlaze@574c6a9

    This should fix NSO-RPC and make it load correctly.

  12. MCMi460 commented on Jul 3, 2023

    @MCMi460
    Owner

    This should now be fixed, as of #87.
    Thanks for bringing our attention to this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions