Results 1 to 6 of 6

Thread: QVector problem

  1. #1
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QVector problem

    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


    Qt Code:
    1. struct MVRObject
    2. {
    3. QString name;
    4. objectType type;
    5. float x,y,z,rotx,roty,rotz,r,g,b,a,sizez,sizey,sizex,radius;
    6. }m_MVR;
    7.  
    8.  
    9. VRML2MVRDlg::VRML2MVRDlg(QWidget *parent)
    10. : QDialog(parent)
    11. {
    12. QVector<MVRObject> MVRObj(1);
    13. MVRObj[0].name = "";
    14. MVRObj[0].x = 0;
    15. MVRObj[0].y = 0;
    16. MVRObj[0].z = 0;
    17. MVRObj[0].rotx = 0;
    18. MVRObj[0].roty = 0;
    19. MVRObj[0].rotz = 0;
    20. MVRObj[0].r = 0;
    21. MVRObj[0].g = 0;
    22. MVRObj[0].b = 0;
    23. MVRObj[0].a = 1;
    24. MVRObj[0].sizez = 0;
    25. MVRObj[0].sizey = 0;
    26. MVRObj[0].sizex = 0;
    27.  
    28. ui.setupUi(this);
    29.  
    30. connect(ui.m_Browse, SIGNAL(clicked()), this, SLOT(on_Browse_clicked()));
    31. // connect(ui.m_Browse, SIGNAL(clicked()),this, SLOT(getFileName()));
    32. connect(ui.m_convert, SIGNAL(clicked()), this, SLOT(on_Convert_clicked()));
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QVector problem

    Is this the only error you get? Did you remember to include <QVector> ?

  3. #3
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVector problem

    sorry for the delayed reply.
    yah I included that - #include <qvector.h>
    I dont know what I am doing wrong.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QVector problem

    qvector.h? Why not <QVector>? Where did you get that error?

  5. #5
    Join Date
    Oct 2006
    Location
    Poznan, Poland
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default

    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
    Last edited by wysota; 19th October 2006 at 10:37. Reason: Merged two posts

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QVector problem

    Quote Originally Posted by piotrek View Post
    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.

  7. The following user says thank you to wysota for this useful post:

    kingslee (13th November 2006)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.