Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73201

For Qt6, reconsider Q*Application(int &argc, char **argv) constructor

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Core: Event loop
    • None

    Description

      QCoreApplication(int &argc, char **argv) implies that the caller (usually the main function) has to provide storage for argc but Qt is free to modify it. And in fact the QApplication constructor docs say "Note: argc and argv might be changed as Qt removes command line arguments that it recognizes." But does it have to be done like that? Seems like argc should be passed by value: an int is never larger than a pointer anyway, and that will ensure that Qt internalizes its own problem (counting the arguments) rather than imposing a (rude) requirement on the application author that "argc might be changed". And it's more or less source compatible.

      What we see in QTBUG-56524 is that a user assumed it was OK to pass argc by value in a subclass (I guess). But it's not, because when the by-value constructor argument is given to the superclass constructor, this requirement is violated: Qt doesn't get to modify the original variable because it's temporary.

      char **argv is convenient because every main() function has it. But it could be const: Qt should not modify either the pointer or the contents of that either.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              srutledg Shawn Rutledge
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes