QVector::size() makes program crash
-
wrote on 20 Apr 2022, 08:37 last edited by
Hi all.
I have a function that looks like this
void IconWidget::changePixmap(int newIndex) { if (newIndex < pixmaps.size()) index = newIndex; updatePixmap(); }
pixmaps is declared as
typedef struct { Pixmap::Index index; QPixmap lightNormal; QPixmap lightActive; QPixmap darkNormal; QPixmap darkActive; } PixmapItem; QVector<PixmapItem> pixmaps;
When I call. QVector::size(), then the program crashes with a segfault.
Any ideas? -
Hi all.
I have a function that looks like this
void IconWidget::changePixmap(int newIndex) { if (newIndex < pixmaps.size()) index = newIndex; updatePixmap(); }
pixmaps is declared as
typedef struct { Pixmap::Index index; QPixmap lightNormal; QPixmap lightActive; QPixmap darkNormal; QPixmap darkActive; } PixmapItem; QVector<PixmapItem> pixmaps;
When I call. QVector::size(), then the program crashes with a segfault.
Any ideas?@Jakob-Clausen I would say, it's not breaking on the size call, but on the function entry point, on the very first thing it has to do with a member variable.
from top right I would say your IconWidget instance is invalid (null)
-
wrote on 20 Apr 2022, 08:47 last edited by
That is interesting.
If I replace the first line in the function with something likeqDebug() << "hello";
Then it also crashes. If you are right, is this what is to be expected?
-
That is interesting.
If I replace the first line in the function with something likeqDebug() << "hello";
Then it also crashes. If you are right, is this what is to be expected?
@Jakob-Clausen jepp
-
wrote on 20 Apr 2022, 10:58 last edited by
Ok. Maybe not quite that.
But your input helped me track down what the problem really was.
Thank you very much for your help.
5/5