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

[REG] QCoreApplication constructor overwrites QCoreApplication::applicationName

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.5.0 RC, 5.5.0
    • 5.5.0 Alpha
    • Core: I/O
    • None
    • f1bfc4266bb0b4a3269d79f6ed34eaa8a1cadbca

    Description

      In commit 6c973dee2cb1686ea32657fff7dced3e611b98ce, a change was made to the QCoreApplication constructor, adding this call:

      // Store app name (so it's still available after QCoreApplication is destroyed)
      coreappdata()->application = d_func()->appName();
      

      This caused some code that we use to break. Essentially, our code is doing the following:

      int main(int argc, char *argv[])
      {
      	QApplication::setApplicationName("My Application Name");
      	qDebug() << "before:" << QApplication::applicationName();
      	QApplication a(argc, argv);
      	qDebug() << "after:" << QApplication::applicationName();
      
      	return a.exec();
      }
      

      which, for a project named "SetApplicationName", prints:

      before: "My Application Name"
      after: "SetApplicationName"
      

      The net effect is that if you call QApplication::setApplicationName() before the QApplication itself is constructed, then whatever application name you set is overwritten with the executable's name.

      This is a problem for us because we call QApplication::setApplicationName() in our application's main() function before the QApplication object itself is created. We do this because we want to control the name of the .ini file created and used by QSettings. Since the QApplication subclass our application uses involves QSettings objects, we need to be able to call QApplication::setApplicationName() before we create the application object and have that name stick.

      Attachments

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

        Activity

          People

            dfaure_kdab David Faure
            aclight Adam Light
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes