Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QApplication app(argc, argv)

I noticed that the main.cpp in a Qt application has to contain the following line:

QApplication app(argc, argv);

I know that argc is the number of command-line arguments, and argv is that array list of command-line arguments. But, the question in my mind is: what are those arguments I'm passing to the constructor and at the same time cannot explicitly see? What is working behind the scences out there?

Thanks.

like image 705
Simplicity Avatar asked Nov 21 '25 16:11

Simplicity


2 Answers

There are no hidden arguments. You can explicitly see every argument- argc, argv. There's nothing in that line of code that's behind the scenes.

like image 193
Puppy Avatar answered Nov 24 '25 06:11

Puppy


From looking at your comments to other answers, I think you are wondering about arguments passed in to your executable if you don't specify any arguments. I'm not sure if it is standardized or what the exceptions may be, but usually in this case, argc will be 1 and argv[0] will be a string that specifies the command that was used to invoke your executable.

Let's assume your executable is called app and resides in /home/user/appdir.

If your current directory is the applications directory and you launch it with 'app' then argc will be 1 and argv[0] will be app.

If you are one directory up from the application's directory and invoke it with ./appdir/app then argc will be 1 and I believe argv[0] will be appdir/app

If you do specify an argument when invoking your application; perhaps you want to tell your application to output debug information like so app debug. In this case, argc will be 2, argv[0] will be app and argv[1] will be debug.

like image 35
Arnold Spence Avatar answered Nov 24 '25 07:11

Arnold Spence



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!