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

Allow a way to alter Qt's behavior in a non-process-wide way by introducing application attributes with string values.

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Core: Other
    • None

    Description

      Currently, you can alter Qt's behavior both with an environment variable and with an application attribute:

      QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on = true)
      

      Unfortunately, it takes a boolean value so it will only allow you to turn a property on or off.

      It would be nice if we could specify a string value.

      Proposal is that a string based setter and getter is added:

      void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, const char *value);  // maybe QByteArray
      
      /*!
        If the attribute has been changed with setAttribute(), it will return that value. Otherwise, if there is a corresponding environment variable for \a attribute it will return that value. Otherwise, it will return the default value for \a attribute.
      */
      QByteArray QCoreApplication::getAttribute(Qt::ApplicationAttribute attribute);
      

      This way, the application itself can ensure a specific behavior by calling setAttribute(). This will apply the behavior just to the Qt instance itself (instead of the whole process as is the case for environment values).
      In addition, we don't have to rely on calling qputenv() (which is ugly and prone to typo errors).

      We can also define a consistent naming scheme from enum value name to environment name (which will make it easier to know what was that environment variable name again).

      This would mean that in Qt, we could replace calls such as

      qputenv("QT_PLUGIN_PATH", pluginPath);
      

      with e.g:

      QCoreApplication::setAttribute(Qt::AA_PluginPath, pluginPath);
      

      With the result that the attribute is not applied for all qt instances in the process, but only for the Qt instance that is associated with that QCoreApplication.

      This have been requested several times as a problem:

      • You run several instances of Qt in the same process, but only want to modify the setting (environment varible) for one of the instances. An example of this is an application that is written in Qt, and loads a plugin that also happen to depend on Qt (but another version). Today, if you modify the environment it might also affect the Qt instance that the plugin depends on, which is usually not desired.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            smd Jan Arve
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes