Fix crash when Android Style is set more than once.

Load again JSON document is it was freed.

Task-number: QTBUG-43111
Change-Id: I22f1de221371b49fec8b3d66ad5f0bd2af9656fe
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
BogDan Vatra 2014-12-11 13:51:48 +02:00
parent 3466950837
commit 21101d9c52
3 changed files with 18 additions and 7 deletions

View File

@ -79,8 +79,11 @@ void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteA
if (resource == "QtActivity")
return QtAndroid::activity();
if (resource == "AndroidStyleData") {
if (m_androidStyle)
if (m_androidStyle) {
if (m_androidStyle->m_styleData.isEmpty())
m_androidStyle->m_styleData = AndroidStyle::loadStyleData();
return &m_androidStyle->m_styleData;
}
else
return Q_NULLPTR;
}

View File

@ -176,7 +176,7 @@ static void setPaletteColor(const QVariantMap &object,
}
}
static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
QJsonObject AndroidStyle::loadStyleData()
{
QString stylePath(QLatin1String(qgetenv("MINISTRO_ANDROID_STYLE_PATH")));
const QLatin1Char slashChar('/');
@ -198,21 +198,29 @@ static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
QFile f(stylePath + QLatin1String("style.json"));
if (!f.open(QIODevice::ReadOnly))
return std::shared_ptr<AndroidStyle>();
return QJsonObject();
QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(f.readAll(), &error);
if (document.isNull()) {
qCritical() << error.errorString();
return std::shared_ptr<AndroidStyle>();
return QJsonObject();
}
if (!document.isObject()) {
qCritical() << "Style.json does not contain a valid style.";
return std::shared_ptr<AndroidStyle>();
return QJsonObject();
}
return document.object();
}
static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
{
std::shared_ptr<AndroidStyle> style(new AndroidStyle);
style->m_styleData = document.object();
style->m_styleData = AndroidStyle::loadStyleData();
if (style->m_styleData.isEmpty())
return std::shared_ptr<AndroidStyle>();
for (QJsonObject::const_iterator objectIterator = style->m_styleData.constBegin();
objectIterator != style->m_styleData.constEnd();
++objectIterator) {

View File

@ -46,12 +46,12 @@ QT_BEGIN_NAMESPACE
struct AndroidStyle
{
static QJsonObject loadStyleData();
QJsonObject m_styleData;
QPalette m_standardPalette;
QHash<int, QPalette> m_palettes;
QHash<int, QFont> m_fonts;
QHash<QByteArray, QFont> m_QWidgetsFonts;
QHash<QByteArray, QFont> m_QWidgetsPalettes;
};
class QAndroidPlatformNativeInterface;