Hi.
Can someone shed a a bit og light on the differences between the following
Hi.
Can someone shed a a bit og light on the differences between the following
What don't you understand about pointers?
They are not that hard to understand, if you think about "storing" the address of a variable (a good analogy is the address of a house, on an envelope you put the pointer (address) not the actual object(house))
I'll tell you a little about the code you post (but i don't think that will help you understand pointers) so please ask what you don't understand
Qt Code:
QVector <int*> *rect; /* rect is a pointer to a QVector <witch stores pointers to ints> carefull with uninitialized pointers, here you don't have the actual QVector, only a pointer*/ QVector <int> *rect; // rect is a pointer to a QVector <witch stores integers> carefull with uninitialized pointers... same as first caseTo copy to clipboard, switch view to plain text mode
Thanks for the reply...
In my project i am using QGraphicsView/Scene and Items .Since i have to have many items which i dont know at runtime so i decided to have a vector of it ..
so after this consideration i wrote something like
but this throws a runtime error..Qt Code:
H_file : QVector <QGraphicsRectItem> rect; then i tried to setRect the rect like CPP_file : rect.at(0).setRect(QReal)....To copy to clipboard, switch view to plain text mode
I am not good at pointers but i searched for QVector in this forum and found something similar to what i had been doing so i tried to implement that code which was
but again a run time error follow..Qt Code:
CPP_file : rect = new QVector<QGraphicsRectItem>(); and the rect->at(0)->setRect...To copy to clipboard, switch view to plain text mode
That is because, this code:
create an empty QVector, and you need to use:Qt Code:
QVector <QGraphicsRectItem> rect; //rect has "place" for 0 elementsTo copy to clipboard, switch view to plain text mode
orQt Code:
QVector <QGraphicsRectItem> rect; rect.push_back(someInstanceOf_QGraphicRectItem); //this add one element (at the end) to the empty QVectorTo copy to clipboard, switch view to plain text mode
rect.at(positon) it's for accessing elements, not for set the elements, so it returns the const element at "position" (with check that the position is valid)Qt Code:
QVector <QGraphicsRectItem> rect(10); //10 is the number of elements, it can grow, with push_back or resize... rect[0] = someInstanceOf_QGraphicRectItem; //or rect[0].set.... ... // this way (operator[]) the position is not checked, so carefullTo copy to clipboard, switch view to plain text mode
QVector reference
Last edited by Zlatomir; 8th June 2010 at 03:05.
salmanmanekia (8th June 2010), zoz (10th June 2010)
Bookmarks