PDA

View Full Version : QVector problem



kingslee
17th October 2006, 21:03
Error : MVRObj undeclared.

In the following code .. I declared MVRObj with QVector<MVRObject>
..
I dont know what's happening .

Is there anything wrong on my coding.

waiting for ur reply




struct MVRObject
{
QString name;
objectType type;
float x,y,z,rotx,roty,rotz,r,g,b,a,sizez,sizey,sizex,rad ius;
}m_MVR;


VRML2MVRDlg::VRML2MVRDlg(QWidget *parent)
: QDialog(parent)
{
QVector<MVRObject> MVRObj(1);
MVRObj[0].name = "";
MVRObj[0].x = 0;
MVRObj[0].y = 0;
MVRObj[0].z = 0;
MVRObj[0].rotx = 0;
MVRObj[0].roty = 0;
MVRObj[0].rotz = 0;
MVRObj[0].r = 0;
MVRObj[0].g = 0;
MVRObj[0].b = 0;
MVRObj[0].a = 1;
MVRObj[0].sizez = 0;
MVRObj[0].sizey = 0;
MVRObj[0].sizex = 0;

ui.setupUi(this);

connect(ui.m_Browse, SIGNAL(clicked()), this, SLOT(on_Browse_clicked()));
// connect(ui.m_Browse, SIGNAL(clicked()),this, SLOT(getFileName()));
connect(ui.m_convert, SIGNAL(clicked()), this, SLOT(on_Convert_clicked()));

}

wysota
17th October 2006, 22:22
Is this the only error you get? Did you remember to include <QVector> ?

kingslee
18th October 2006, 16:35
sorry for the delayed reply.
yah I included that - #include <qvector.h>
I dont know what I am doing wrong.

wysota
18th October 2006, 16:56
qvector.h? Why not <QVector>? Where did you get that error?

piotrek
19th October 2006, 11:30
Hi,

try to do push_back( ... ) after declaration od QVector.
Your Vector is empty.

And next.
When you would like to use a vector, your class (saved in vector) must have default constructor (always), copy constructor and operator= ( not always).

regards
piotrek

wysota
19th October 2006, 11:42
try to do push_back( ... ) after declaration od QVector.
Your Vector is empty.
I think that's not the point. As far as I understand, the code doesn't compile so there is something violating C++ syntax. If the problem would be about an empty vector, the code would compile. Moreover I compiled the code myself and it worked fine, so there is probably some other part of code causing the error (probably the vector is used outside of the constructor as it is declared as a local object so it's destroyed when the constructor returns).


When you would like to use a vector, your class (saved in vector) must have default constructor (always), copy constructor and operator= ( not always).


If you don't implement your own constructor, copy constructor and assignment operator, the compiler will make them for you. For classes that doesn't have pointers as their members and that don't need any special initialisation, those compiler made methods will suffice.