diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index 3e172dc..62b28c6 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -106,7 +106,13 @@ public: private: BR_PROPERTY(Mode, mode, Encoded) - mutable QThreadStorage nam; + // The reasons for this data structure are as follows: + // 1) The QNetworkAccessManager must be used in the thread that _created_ it, + // hence the use of `QThreadStorage`. + // 2) The QThreadStorage must be deleted _after_ the threads that added QNetworkAccessManager + // to it are deleted, hence the `static` ensuring that `nam` is deleted at program termination, + // long after the threads that created QNetworkAccessManager are deleted. + static QThreadStorage nam; void project(const Template &src, Template &dst) const { @@ -165,6 +171,7 @@ private: } } }; +QThreadStorage DownloadTransform::nam; BR_REGISTER(Transform, DownloadTransform)