Why do I need “sys.argv” to start a QApplication in PyQt?

有些话、适合烂在心里 提交于 2019-12-03 11:50:42

问题


I try to understand what PyQt does. And one of the first things I didn't, was:

QApplication(sys.argv)

Why do I have to give QApplication this argument? I know what sys.argv does. But in my Scripts I wouldn't need it.


回答1:


This calls the constructor of the C++ class QApplication. It uses sys.argv (argc and argv in C++) to initialize the QT application. There are a bunch of arguments that you can pass to QT, like styles, debugging stuff and so on.

Take a look at this for a full list of the options.




回答2:


QApplication takes a list of strings as input.

So you can forward sys.argv or simply an empty list:

app = QApplication([])


来源:https://stackoverflow.com/questions/27940378/why-do-i-need-sys-argv-to-start-a-qapplication-in-pyqt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!