I'm new to python and PyQt. When I studyting how to code with PyQt5, I see many people initialize the QApplication object in such way:
app = QtWidgets.QApplication([])
It's legal, but how do I realize it?
I guess that its because the paraments of QApplication() is like (argc, **argv), so an empty list is useful to make a default initialization. But I dont really know how the class works. May I just use QtWidgets.QApplication(sys.argv) to avoid any trouble?
QAplication
takes a list as a positional argument, so it won't work without it. That list can contain additional instructions like [-style, fusion]
, but QApplication will run fine without additional instructions (empty list).
The 'proper' way to initialise QApplication is:
app = QApplication(sys.argv)
That way any arguments that were used to start the program are passed on to QApplication.
The empty list you're seeing is probably from people providing a Minimal, Reproducible Example. When the problem at hand doesn't have anything to do with arguments for QApplication, you can just use an empty list.