Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant run App Error: QWidget: Must construct a QApplication before a QWidget #6

Open
Proktologe opened this issue May 31, 2022 · 2 comments

Comments

@Proktologe
Copy link

I currently start the programm like so:

class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
    
     def initUI(self):
        print("UI inited: MainWindow")
        self.SaveButton.clicked.connect(self.OnBttClicked_Save)
        switch_control = SwitchControl()
        hbox = QHBoxLayout()
        hbox.addWidget(switch_control, Qt.AlignCenter, Qt.AlignCenter)     
        self.setLayout(hbox)


if __name__ == "__main__":
    app = QApplication([])
    
    form_MainWindow = MainWindow() ###<-- in here a try to create the SwitchControl - like in your example
    form_MainWindow.show()

    sys.exit(app.exec())

Ui_MainWindow is a Window made in QT Designer:

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
           if not MainWindow.objectName():
                   MainWindow.setObjectName(u"MainWindow")
           MainWindow.resize(823, 656)
           .
           . #Design code goes here
           .

I allways get the Exception: QWidget: Must construct a QApplication before a QWidget

@Prx001
Copy link
Owner

Prx001 commented Jun 1, 2022

Hey there Proktologe!

I checked your code and it runs well..

The exception you specified happens when you create QWidget objects before making a QApplication one.

You can send your project files to my email for further assistance.

@Redoblue
Copy link

Redoblue commented Jun 3, 2024

@Proktologe You should use PyQt5, PySide series are not supported according to the codes. Or you can try to modify it, just rename some identifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants