Skip to content

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

@Proktologe

Description

@Proktologe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions