Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 992
Sir2B Avatar asked Jan 14 '15 10:01

Sir2B


People also ask

What is the purpose of app QApplication SYS argv?

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.

What is QApplication in PYQT?

The QApplication class manages the GUI application's control flow and main settings. It specializes in the QGuiApplication with some functionality needed for QWidget based applications. It handles widget specific initialization, finalization.

What is SYS argv in Python?

sys. argv is a list in Python that contains all the command-line arguments passed to the script. It is essential in Python while working with Command Line arguments.

What is SYS in pyqt5?

The sys. argv parameter is a list of arguments from a command line. Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.


2 Answers

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.

like image 146
dmg Avatar answered Sep 19 '22 08:09

dmg


QApplication takes a list of strings as input.

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

app = QApplication([]) 
like image 20
sebastian Avatar answered Sep 17 '22 08:09

sebastian