Why VerticalHeaderItem cause crit.error
-
wrote on 6 Nov 2018, 21:27 last edited by
When i add any action to my VertHItem - in runtime it cause crit error and the program stop working. I've included QHeaderView, certain Item indeed exist, but i simply can't set text for it:
if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
That code assures that item at '0' exist and it's label is 1, which is true, it 1 by default in my app.
P.S. here is it in documentation
-
Hi
You should check its not NULL
try
qDebug() << "item = " << tabWidGuide.verticalHeaderItem(0); -
When i add any action to my VertHItem - in runtime it cause crit error and the program stop working. I've included QHeaderView, certain Item indeed exist, but i simply can't set text for it:
if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
That code assures that item at '0' exist and it's label is 1, which is true, it 1 by default in my app.
P.S. here is it in documentation
@Engelard said in Why VerticalHeaderItem cause crit.error:
if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
To add to @mrjj : you should ALWAYS check pointers before dereferencing them!
if(tabWidGuide.verticalHeaderItem(0) && tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
-
When i add any action to my VertHItem - in runtime it cause crit error and the program stop working. I've included QHeaderView, certain Item indeed exist, but i simply can't set text for it:
if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
That code assures that item at '0' exist and it's label is 1, which is true, it 1 by default in my app.
P.S. here is it in documentation
And that's exactly the difference between pointers and references you have to understand.
Pointers have to be checked against nullptr before de-referencing, references can always be used.
-
@Engelard said in Why VerticalHeaderItem cause crit.error:
if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
To add to @mrjj : you should ALWAYS check pointers before dereferencing them!
if(tabWidGuide.verticalHeaderItem(0) && tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
wrote on 7 Nov 2018, 09:35 last edited by JonB 11 Jul 2018, 09:35 -
wrote on 7 Nov 2018, 15:04 last edited by
Tnx for all advices for checking item, now it shows that header does'nt exist. BUT. Why it exist in the app, and it returning like it does'nt?
-
Tnx for all advices for checking item, now it shows that header does'nt exist. BUT. Why it exist in the app, and it returning like it does'nt?
Why it exist in the app, and it returning like it does'nt?
- How do you set it?
- Do you set it before your read it back?
-
Why it exist in the app, and it returning like it does'nt?
- How do you set it?
- Do you set it before your read it back?
-
@aha_1980 i didn't set anything, i assume that it set by default, so why would i set it..
@Engelard said in Why VerticalHeaderItem cause crit.error:
i assume that it set by default,
It isn't.
2/9