PDA

View Full Version : QGraphicsItem setpos()



qtuser20
27th July 2009, 23:12
Hi

I am saving out the properties of a textitem that was created for an image and constructing the item while reloading the image.However i seem to be making some mistake with pos()
Here is what i use:

QDataStream out(&itemfile);
....
.....
out<<textItem->pos();


While reading in ,

QPoint p;
in >> p;
textItem->setPos(p);

this does not work .If i try to test using setPos(100,100), then the item is displayed.
Apparently am making some mistake..

Thanks

wysota
28th July 2009, 00:12
What does this return?

qDebug() << p;
Are you sure you're in sync with the stream? Maybe you forgot to write or read something and the contents of the stream is different than you expect?

qtuser20
28th July 2009, 23:01
Hi

While saving out the position, i use


out<<(qint32(textItem->pos().x()));
out<<(qint32(textItem->pos().y()));
qDebug() << (qint32(textItem->pos().x()));
qDebug() << (qint32(textItem->pos().y()));

qDebug() returns the following values:
-----------------------------------------------------
478
46
276
366

While reading in,


qint32 px;
qint32 py;

in >> px;
in >> py;
qDebug() << px;
qDebug() << py;
.....
textItem->pos().setX(px);
textItem->pos().setY(py);

qDebug() returns the following erroneous values:
1075786547
858993459
0
0

I checked the sequence, am writing out and reading in proper order.Is my syntax for setting the coordinates correct ? What am i missing ?

Thank you

qtuser20
28th July 2009, 23:06
I am able to read back other attributes like text,font etc.So the issue is related only to position.

wysota
29th July 2009, 07:41
Please provide a minimal compilable example reproducing the problem.

c_srikanth1984
29th July 2009, 09:06
Try to save
While Writing:

QPointF p;
p=TextItem->pos();
out<<p;
While Reading:

QPointF p;
in>>p;
TextItem->setPos(p);

I have done like this and I got.
One more thing if there are many No. of Items Whose position is to be saved better go for
QList<QPointF *> and save the QList.

qtuser20
3rd August 2009, 17:17
Thank you .That helped.