Usage of QT::UserRole in Qtreewidgetitem
Hi,
I am having issues with using Qt::UserRole with Qtreewidgetitem.
Here's my code :
Code:
UGS::AsciiString Hdrstr = "Header";
RootWidget->setData(0, Qt::UserRole + 1, Headerqv);
And finally retrieving the value:
Code:
StrValue = Widgetitem->data(0, Qt::UserRole + 1);
QString strval
= StrValue.
toString();
if (strval.toStdString() == "Header")
In this line :
if (strval.toStdString() == "Header")
there's no value of the string. Can anyone suggest what am I doing wrong over here ?
Thank you !
Re: Usage of QT::UserRole in Qtreewidgetitem
Are RootWidget and Widgetitem the same pointer?
Cheers,
_
Re: Usage of QT::UserRole in Qtreewidgetitem
They are different pointers but they are pointing to the same item. So, yeah they got same value.
But even I do:
Code:
RootWidget->setData(0, Qt::UserRole + 1, Headerqv);
QVariant StrValue
= RootWidget
->data
(0, Qt
::UserRole + 1);
QString strval
= StrValue.
toString();
string str = strval.toStdString();
To check the value right after setting the data, str value is still NULL , mean an empty string"" .
Not sure why.
Thanks,
Re: Usage of QT::UserRole in Qtreewidgetitem
Quote:
Originally Posted by
h4harman
They are different pointers but they are pointing to the same item.
If it is not the same pointer, how can it be the same object?
Quote:
Originally Posted by
h4harman
But even I do:
Code:
RootWidget->setData(0, Qt::UserRole + 1, Headerqv);
QVariant StrValue
= RootWidget
->data
(0, Qt
::UserRole + 1);
QString strval
= StrValue.
toString();
string str = strval.toStdString();
To check the value right after setting the data, str value is still NULL , mean an empty string"" .
Have you checked Headerqv? Does it contain the string?
Cheers,
_
Re: Usage of QT::UserRole in Qtreewidgetitem
Quote:
If it is not the same pointer, how can it be the same object?
Well I needed 2 pointers to point to the same address. So it's the same object coz they are pointing to the same value. I think that's what you wanted to say.
But anyhow, I got the solution. I was just writing some extra lines of code for no reason. I did the following :
Code:
RootWidget->setData(0, Qt::UserRole, Headerqv);
QVariant StrValue
= RootWidget
->data
(0, Qt
::UserRole);
QString strval
= StrValue.
toString();
string str = strval.toStdString();
But thanks for all the help :)
Regards,
Re: Usage of QT::UserRole in Qtreewidgetitem
Quote:
If it is not the same pointer, how can it be the same object?
I think now I know why you pointed that out. So it seems, widgets are individual objects. I can't use another widget item to point to it and use it values. I thought I could do that.