Qt-interest Archive, August 2006
QVariant to Labels
Message 1 in thread
Hi,
I am trying to read data from my tree model (QAbstractTreeModel). When
passing the index and Qt::DisplayRole to the data() function I get QVariant.
Is there a way I can read the table contents without data? If not, how can I
add these QVariant values returned by the data to a messageBox or a QLabel??
Thanks
-Subir
Message 2 in thread
Subir Jhanb wrote:
> Hi,
>
> I am trying to read data from my tree model (QAbstractTreeModel). When
> passing the index and Qt::DisplayRole to the data() function I get
> QVariant. Is there a way I can read the table contents without data? If
> not, how can I add these QVariant values returned by the data to a
> messageBox or a QLabel??
>
> Thanks
> -Subir
QVariant can be converted to string.
QVariant qv;
QLavel lbl(this);
lbl.setText(qv.toString());
--
[ signature omitted ]
Message 3 in thread
On Thursday 03 August 2006 19:11, Subir Jhanb wrote:
> Hi,
>
> I am trying to read data from my tree model (QAbstractTreeModel). When
> passing the index and Qt::DisplayRole to the data() function I get
> QVariant. Is there a way I can read the table contents without data? If
> not, how can I add these QVariant values returned by the data to a
> messageBox or a QLabel??
pTreeWidgetItem->text(0)
or
pTreeWidgetItem->data(0, Qt:DisplayRole).toString()
Jeff
--
[ signature omitted ]
Message 4 in thread
On 03.08.06 19:50:38, Jeffrey Laramie wrote:
> On Thursday 03 August 2006 19:11, Subir Jhanb wrote:
> > Hi,
> >
> > I am trying to read data from my tree model (QAbstractTreeModel). When
> > passing the index and Qt::DisplayRole to the data() function I get
> > QVariant. Is there a way I can read the table contents without data? If
> > not, how can I add these QVariant values returned by the data to a
> > messageBox or a QLabel??
>
> pTreeWidgetItem->text(0)
>
> or
>
> pTreeWidgetItem->data(0, Qt:DisplayRole).toString()
That doesn't help if the OP uses his own tree model (which he does).
Andreas
--
[ signature omitted ]
Message 5 in thread
On Thursday 03 August 2006 22:16, Andreas Pakulat wrote:
> On 03.08.06 19:50:38, Jeffrey Laramie wrote:
> > On Thursday 03 August 2006 19:11, Subir Jhanb wrote:
> > > Hi,
> > >
> > > I am trying to read data from my tree model (QAbstractTreeModel). When
> > > passing the index and Qt::DisplayRole to the data() function I get
> > > QVariant. Is there a way I can read the table contents without data? If
> > > not, how can I add these QVariant values returned by the data to a
> > > messageBox or a QLabel??
> >
> > pTreeWidgetItem->text(0)
> >
> > or
> >
> > pTreeWidgetItem->data(0, Qt:DisplayRole).toString()
>
> That doesn't help if the OP uses his own tree model (which he does).
Hi Andreas,
The 4.1.3 docs show a QAbstractTableModel but not a QAbstractTreeModel. Is
this a 4.2 feature? Wouldn't he still need to use QTreeWidgetItems even using
a custom model?
Jeff
--
[ signature omitted ]
Message 6 in thread
On 03.08.06 16:11:05, Subir Jhanb wrote:
> I am trying to read data from my tree model (QAbstractTreeModel). When
> passing the index and Qt::DisplayRole to the data() function I get QVariant.
> Is there a way I can read the table contents without data? If not, how can I
> add these QVariant values returned by the data to a messageBox or a QLabel??
QVariant is just a container for simple types, like strings, integers,
pictures. The reasone behind data returnin a QVariant is that you can't
overload on return type in C++ thus you'd have
dataString
dataInt
dataFloat
and so on. Not a very nice API.
So, when your data function puts a QString into the QVariant (i.e.
returns a QString), then you can use QVariants toString() method to get
it out again. BTW: This is explained in the reference documentation for
QVariant.
Andreas
--
[ signature omitted ]