Warn when setting attributes after QCoreApplication is created
It's a recurring bug seen in user code and a warning will help reduce it. Warns only for the attributes that have such requirement in the docs, but maybe we should be more strict and warn for any attribute. Change-Id: I68148521953221ad0e8be1028181f52a7f22d2cc Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
f6f0a9f3f6
commit
e9e16c7464
@ -46,6 +46,7 @@
|
||||
#include "qcoreevent.h"
|
||||
#include "qeventloop.h"
|
||||
#endif
|
||||
#include "qmetaobject.h"
|
||||
#include "qcorecmdlineargs_p.h"
|
||||
#include <qdatastream.h>
|
||||
#include <qdebug.h>
|
||||
@ -966,6 +967,10 @@ bool QCoreApplication::isSetuidAllowed()
|
||||
Sets the attribute \a attribute if \a on is true;
|
||||
otherwise clears the attribute.
|
||||
|
||||
\note Some application attributes must be set \b before creating a
|
||||
QCoreApplication instance. Refer to the Qt::ApplicationAttribute
|
||||
documentation for more information.
|
||||
|
||||
\sa testAttribute()
|
||||
*/
|
||||
void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on)
|
||||
@ -974,6 +979,27 @@ void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on)
|
||||
QCoreApplicationPrivate::attribs |= 1 << attribute;
|
||||
else
|
||||
QCoreApplicationPrivate::attribs &= ~(1 << attribute);
|
||||
if (Q_UNLIKELY(qApp)) {
|
||||
switch (attribute) {
|
||||
case Qt::AA_EnableHighDpiScaling:
|
||||
case Qt::AA_DisableHighDpiScaling:
|
||||
case Qt::AA_PluginApplication:
|
||||
case Qt::AA_UseDesktopOpenGL:
|
||||
case Qt::AA_UseOpenGLES:
|
||||
case Qt::AA_UseSoftwareOpenGL:
|
||||
case Qt::AA_ShareOpenGLContexts:
|
||||
#ifdef QT_BOOTSTRAPPED
|
||||
qWarning("Attribute %d must be set before QCoreApplication is created.",
|
||||
attribute);
|
||||
#else
|
||||
qWarning("Attribute Qt::%s must be set before QCoreApplication is created.",
|
||||
QMetaEnum::fromType<Qt::ApplicationAttribute>().valueToKey(attribute));
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user