Results 1 to 9 of 9

Thread: vector of vector

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default vector of vector

    Hi, I need declare a vector of vector; is it possible? thanks
    Qt Code:
    1. vector<QSpinBox*> sbz;
    2. vector<QSpinBox*> sby;
    3. vector<QSpinBox*> sbz;
    4. vector<vector> sb; //error
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vector of vector

    Quote Originally Posted by mickey
    Hi, I need declare a vector of vector; is it possible?
    Yes, but you must specify the type which the inner vector will hold.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: vector of vector

    Ok, but i don't know how push in it elements:
    Qt Code:
    1. vector<QSpinBox> sb;
    2. sb.push_back(sbx); //error
    To copy to clipboard, switch view to plain text mode 

    Another Q: Wich is better (between 2 below)? Thanks
    Qt Code:
    1. vector<QSpinBox*> sbz;
    2. vector<QSpinBox> sbz;
    To copy to clipboard, switch view to plain text mode 
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vector of vector

    You can't copy Qt widgets, so you can't have a vector of spin boxes. Use a vector of pointers instead.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: vector of vector

    if you referred to this, don't compile...
    Qt Code:
    1. vector<QSpinBox*> sbx;
    2. vector<QSpinBox*> sb;
    3. sb.push_back(sbx); //error
    To copy to clipboard, switch view to plain text mode 

    Maybe this?
    Qt Code:
    1. vector<QSpinBox**> sb;
    2. sb.push_back(&sbx[0]);
    To copy to clipboard, switch view to plain text mode 
    Last edited by mickey; 5th June 2006 at 00:44.
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vector of vector

    Quote Originally Posted by mickey
    if you referred to this, don't compile...
    If you want a vector of vectors of pointers to spin boxes you need:
    Qt Code:
    1. vector<QSpinBox*> sbx;
    2. vector< vector<QSpinBox*> > sb;
    3. sb.push_back(sbx); // no error
    To copy to clipboard, switch view to plain text mode 

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

    mickey (5th June 2006)

  8. #7
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vector of vector

    Jacek,

    How does that work again? When setting an object equal to another object in c++, it doesn't call the copy constructor, but rather the operator =, right? So in either case we can't "copy" widgets? That is, even when evoking the copy constructor?

  9. #8
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vector of vector

    Quote Originally Posted by kroenecker
    Jacek,

    How does that work again? When setting an object equal to another object in c++, it doesn't call the copy constructor, but rather the operator =, right? So in either case we can't "copy" widgets? That is, even when evoking the copy constructor?
    widgets can't be copied! All you can use is a pointer (or a reference depending what you want to do, but a pointer is better anyway) to them that can be used to modify them.
    Current Qt projects : QCodeEdit, RotiDeCode

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: vector of vector

    Quote Originally Posted by kroenecker
    So in either case we can't "copy" widgets?
    Yes, you can't copy widgets, but here you have a vector of pointers to widgets.

Similar Threads

  1. vector
    By mickey in forum General Programming
    Replies: 1
    Last Post: 26th May 2006, 19:57
  2. <vector> and new
    By mickey in forum General Programming
    Replies: 11
    Last Post: 18th May 2006, 15:27
  3. model conception
    By xavier in forum General Programming
    Replies: 7
    Last Post: 10th May 2006, 09:34
  4. vector of objects
    By mickey in forum General Programming
    Replies: 2
    Last Post: 8th May 2006, 20:13
  5. vector memory allocation
    By TheKedge in forum General Programming
    Replies: 1
    Last Post: 23rd March 2006, 17:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.