V
V
vovaflamed2021-11-26 20:13:21
PyQt
vovaflamed, 2021-11-26 20:13:21

How to fix pyqt error?

I get an error:

Must construct a QApplication before a QWidget
main.py:

import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from windows.mainWindow import MainWindow



if __name__ == '__main__':
    app = QApplication(sys.argv)

    window = MainWindow()
    window.show()

    
    sys.exit(app.exec())

MainWindow.py:
from PyQt5.QtWidgets import  QMainWindow

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setWindowTitle('MainWindow')

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Osmanov Osman, 2021-11-26
@OSMANOF

class MainWindow(QMainWindow):
    def __init__(self):
        super(QMainWindow, self).__init__()
        self.setWindowTitle('MainWindow')

N
nvlveu, 2021-11-26
@nvlveu

Because in main.py you use PySide6, and in MainWindow.py PyQt5

A
Andy_U, 2021-11-26
@Andy_U

You have in main.py import PySide6, in MainWindow.py import PyQt5. Either put on shorts, or take off the cross :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question