I ran into a strange problem with QStyle.
-
I am using QT5, but I have occasionally encountered problems during my development.
When I use this method to refresh the widget,
widget->setProperty("Hovered", "true"); widget->style()->unpolish(widget); widget->style()->polish(widget);
I occasionally see a crash stack like this
int std::__1::__cxx_atomic_fetch_sub<int>(std::__1::__cxx_atomic_base_impl<int>*, int, std::__1::memory_order) (atomic:1072) std::__1::__atomic_base<int, true>::fetch_sub(int, std::__1::memory_order) (atomic:1725) std::__1::__atomic_base<int, true>::operator--() (atomic:1760) bool QAtomicOps<int>::deref<int>(std::__1::atomic<int>&) (qatomic_cxx11.h:289) QBasicAtomicInteger<int>::deref() (qbasicatomic.h:119) QSharedDataPointer<QStyleSheetImageData>::~QSharedDataPointer() (qshareddata.h:93) QSharedDataPointer<QStyleSheetImageData>::~QSharedDataPointer() (qshareddata.h:93) QRenderRule::~QRenderRule() (qstylesheetstyle.cpp:510) QRenderRule::~QRenderRule() (qstylesheetstyle.cpp:510) QHashData::free_helper(void (*)(QHashData::Node*)) (qhash.cpp:572) QHashData::free_helper(void (*)(QHashData::Node*)) (qhash.cpp:572) QHash<int, QHash<unsigned long long, QRenderRule>>::freeData(QHashData*) (qhash.h:619) QHash<int, QHash<unsigned long long, QRenderRule>>::~QHash() (qhash.h:250) QHash<int, QHash<unsigned long long, QRenderRule>>::~QHash() (qhash.h:250) QHashNode<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::~QHashNode() (qhash.h:147) QHashNode<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::~QHashNode() (qhash.h:147) QHash<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::deleteNode2(QHashData::Node*) (qhash.h:595) QHash<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::deleteNode(QHashNode<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>*) (qhash.h:585) QHash<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::remove(QObject const* const&) (qhash.h:824) QStyleSheetStyle::unpolish(QWidget*) (qstylesheetstyle.cpp:2992)
Does anyone know what caused this?
-
This sounds similar to https://bugreports.qt.io/browse/QTBUG-69204
-
@Christian-Ehrlicher Sorry, I forgot to mention my development environment. I am currently using Qt version 5.15.14. The development machine is MacOS m1.
I see this crash you mentioned (https://bugreports.qt.io/browse/QTBUG-69204) was fixed in 5.12.4, 5.14.0 Alpha.
When I was using setStyleSheet directly, I occasionally had updateObjects crash.setStyleSheet(QString("a{b:c}"));
The crash stack looks like
int std::__1::__cxx_atomic_load<int>(std::__1::__cxx_atomic_base_impl<int> const*, std::__1::memory_order) (atomic:1006) std::__1::__atomic_base<int, false>::load(std::__1::memory_order) const (atomic:1615) int QAtomicOps<int>::loadRelaxed<int>(std::__1::atomic<int> const&) (qatomic_cxx11.h:239) QBasicAtomicInteger<int>::loadRelaxed() const (qbasicatomic.h:107) QtPrivate::RefCount::deref() (qrefcount.h:66) QHash<QString, QVariant>::~QHash() (qhash.h:250) QHash<QString, QVariant>::~QHash() (qhash.h:250) QRenderRule::~QRenderRule() (qstylesheetstyle.cpp:510) QRenderRule::~QRenderRule() (qstylesheetstyle.cpp:510) QHashData::free_helper(void (*)(QHashData::Node*)) (qhash.cpp:572) QHashData::free_helper(void (*)(QHashData::Node*)) (qhash.cpp:572) QHash<int, QHash<unsigned long long, QRenderRule>>::freeData(QHashData*) (qhash.h:619) QHash<int, QHash<unsigned long long, QRenderRule>>::~QHash() (qhash.h:250) QHash<int, QHash<unsigned long long, QRenderRule>>::~QHash() (qhash.h:250) QHashNode<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::~QHashNode() (qhash.h:147) QHashNode<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::~QHashNode() (qhash.h:147) QHash<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::deleteNode2(QHashData::Node*) (qhash.h:595) QHash<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::deleteNode(QHashNode<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>*) (qhash.h:585) QHash<QObject const*, QHash<int, QHash<unsigned long long, QRenderRule>>>::remove(QObject const* const&) (qhash.h:824) updateObjects(QList<QObject const*> const&) (qstylesheetstyle.cpp:2769) QStyleSheetStyle::repolish(QWidget*) (qstylesheetstyle.cpp:2969)
So I changed to use
QStyleSheetStyle::unpolish
, hoping to reduce the occurrence of collapse. But occasionally there is a crash. -
Please provide a minimal, compilable example of your problem. Check it with a recent Qt6 version and if the issue still exists, create a bug report (or post it here and I'll take a look on it).