I'm learning C++ with Qt and noticed that QApplication is commonly created with `QApplication app(argc, argv);`. What do `int argc` and `char *argv[]` represent, and why does Qt need them?
3 Answers
They represent command-line arguments. `argc` is the number of arguments, while `argv` is an array of C-style strings containing those arguments. If you run `myprogram hello 123`, you’ll typically get `argc == 3`, with `argv[0]` set to the program name, `argv[1]` set to `"hello"`, and `argv[2]` set to `"123"`.
A typical C++ entry point looks like `int main(int argc, char* argv[])`. The `char* argv[]` part can be read as an array of pointers to characters, or more simply, an array of strings. There is also a null pointer at `argv[argc]` to mark the end of the array.
Qt accepts these values so it can inspect and process command-line options intended for Qt. For a basic application, you usually don’t need to interpret them yourself—just declare them in `main` and pass them to the constructor: `int main(int argc, char* argv[]) { QApplication app(argc, argv); return app.exec(); }`

That makes sense. I had been using a `main()` with no parameters, so I can change it to accept `argc` and `argv` and pass them to QApplication.