https://bugs.kde.org/show_bug.cgi?id=436350

--- Comment #43 from Konrad Materka <[email protected]> ---
(In reply to Vaclav Masin from comment #41)
> I've been thinking... would it make any sense for me to try to debug it
> myself? I mean going step by step over the code, watching the data structure
> that holds the systray data along the way and waiting for it to get broken
> at some point? I'd obviously need a nudge in the right direction from you as
> to where in the code to start etc.

That would be the only feasible way :)

the problem is around line:
m_items.append(item);
in SystemTrayModel. Unfortunately somewhere inside QVector implementation.
Initially QVector has very low capacity (to save memory), when one adds more
items more memory is allocated (0 -> 2 -> 6 -> 14 -> 30 -> 62...). Your problem
occurs when capacity goes from 6 to 14 - probably QString "source" is wrongly
moved which ends in empty string (""). Test vector app does exactly the same
QVector resizing but it works correctly...

It is very unlikely that this is a problem in Qt library, it is used by
thousands if not millions, this kind of issue would be detected long time ago.
So must be a problem with QVector usage. I wrote this code (SystemTrayModel)
but I'm not an C++ expert (mostly Java). Probably there is non-obvious but
trivial things that should be added.

There are few things you can check:

* this is my best guess, in systemtraymodel.h add:
Q_DECLARE_TYPEINFO(StatusNotifierModel::Item, Q_MOVABLE_TYPE);
StatusNotifierModel::Item must be public - it is after my last patch, but you
can do better and:

* move struct Item outside of StatusNotifierModel. In cpp file usage would be
just Item, instead of StatusNotifierModel::Item. you can change struct name to
something like struct StatusNotifierModelItem

* add deep copy when assigning item.source (this should never be need, only to
test if there is a problem with data sharing in Qt):
#include <QDeepCopy>
item.source = QDeepCopy(sourceName);

* this is ugly hack, but you can allocate bigger space for m_items in
constructor of SystemTrayModel:
    m_items.resize(1000);
    m_items.clear();
this is unacceptable in production code but can confirm my hypothesis about
QVector resize (and bad reallocation)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to