What do `argc` and `argv` mean in a Qt application?

September 24, 2026 3 answers
Asked by Tizzybee
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?

Answers

valley.crossing
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(); }`

Tizzybee: 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.

Reply to this answer
a3+octave
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.
Reply to this answer
circuit.breaker.label
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"`.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions