QTimeZone::availableTimeZoneIds() crashes on Mac (Qt 5.2.0 until 5.3.0alpha)
-
I'm not sure if this is a Qt bug or if I'm doing something wrong. Here is the situation :
In my application I have to make a network request and then do something that involves calling QTimeZone::availableTimeZoneIds(). I managed to track down the problem and this is the most compact code that reproduces the error.
main.cpp
@#include "LocationManager.h"int main(int argc, char argv[])
{
QGuiApplication a(argc, argv);
LocationManager lm = new LocationManager();
return a.exec();delete lm;
}@
LocationManager.cpp
@#include <QTimeZone>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
LocationManager::LocationManager(QObject parent) :
QObject(parent)
{
QNetworkAccessManager nam = new QNetworkAccessManager(this);
connect (nam, SIGNAL(finished(QNetworkReply)), this, SLOT(onNetworkManagerFinished(QNetworkReply)));QUrl url; nam->get(QNetworkRequest(url));
}
void LocationManager::onNetworkManagerFinished(QNetworkReply *reply)
{
QTimeZone::availableTimeZoneIds();
}@LocationManager.h is as simple as it gets.
This codes crashes on Mac OSX 10.9.2, Qt5.2.1. The crash is situated somewhere in QCocoaEventDispatcher::processEvents() and happens a little bit after QTimeZone::availableTimeZoneIds() is called. I can not give any further details as I do not have the necessary debugging libraries
I found several ways not to make it crash, all of which are not acceptable solutions :
replace QGuiApplication with QCoreApplication. Not an option for my app.
not calling QTimeZone::availableTimeZoneIds() after having used the network manager. Not an option either.
call QTimeZone::availableTimeZoneIds() before using the QNetworkAccessManager and save the results for later use. Does not crash, but what if something else starts crashing later?
Could someone have a look at this as I have already spent a lot of time on tracking down the problem and using QTimeZone is critical for my application. Would it be possible for somebody to try to reproduce this?
Thank you for your time. Qt is great. I have certainly gained more time using it than I have lost debugging it.
-
Hi,
Can you check whether it also happens with QApplication ?
And is it reproducible with any url ? If not, can you give an url example ? -
Thank you for your quick reply.
Yes it also crashes with QApplication.
Any url produces the crash, event an empty one.
I also tried calling availableTimeZoneIds() statically and saving the results in a static QList<QByteArray>. Still the application crashes shortly after a QTimeZone is created using one of those ids in the list.So this is another version of the crashing code :
LocationManager.h
@class LocationManager : public QObject
{
Q_OBJECT
public:
LocationManager(QObject *parent = 0);private slots:
void onNetworkManagerFinished();private:
static const QList<QByteArray> m_timeZones;
};@LocationManager.cpp
@const QList<QByteArray> LocationManager::m_timeZones(QTimeZone::availableTimeZoneIds());LocationManager::LocationManager(QObject *parent) :
QObject(parent)
{
QNetworkAccessManager nam = new QNetworkAccessManager(this);
connect (nam, SIGNAL(finished(QNetworkReply)), this, SLOT(onNetworkManagerFinished()));QUrl url; nam->get(QNetworkRequest(url));
}
void LocationManager::onNetworkManagerFinished()
{
foreach (QByteArray ba, m_timeZones) {
qDebug() << ba; // OK
qDebug() << QTimeZone(); // still OK
// does not crash if the following line is commented
qDebug() << QTimeZone(ba);
}
}@ -
Since you can reproduce that repeatedly, please open a bug report "here":http://bugreports.qt-project.org providing a minimal compilable example that reproduces the problem
-
Filed a bug report :
Bug No : 37582
https://bugreports.qt-project.org/browse/QTBUG-37582Thank you for your time. Hope a workaround is found quickly.
-
For those interested in using QTimeZone in a multi-threaded application, well don't!
Although a first fix has been attempted, there are other problems hidden.
QTimeZone is still very buggy on Mac and might make your multi-threaded application crash at any point without giving you any clues about were the problem is situated. Very difficult debugging. This is true for versions 5.2.0, 5.2.1 and 5.3.0alpha (as of this date).
I'll keep posting here as soon as there's something new. The Qt team seems really active on this kind of bugs.