Results 1 to 4 of 4

Thread: Multi-dimensional objects array

  1. #1
    Join Date
    Apr 2010
    Location
    Rzeszów \ Poland
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Multi-dimensional objects array

    Hello.
    I want to create multi-dimensional array of objects, but I have problem with it.
    For example:
    Qt Code:
    1. QTableWidgetItem *item = new QTableWidgetItem[10][10];
    To copy to clipboard, switch view to plain text mode 
    call me:
    Qt Code:
    1. (...)mainwindow.cpp:54: error: cannot convert ‘QTableWidgetItem (*)[10]’ to ‘QTableWidgetItem*’ in initialization
    To copy to clipboard, switch view to plain text mode 

    What else do it to resolve error?

  2. #2
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Multi-dimensional objects array

    This is on so many levels wrong that just telling you the solution would not help you at all. Maybe you should read the basics on arrays in C++ first:

    http://www.cplusplus.com/doc/tutorial/arrays/
    http://www.exforsys.com/tutorials/c-...al-arrays.html
    http://www.cplusplus.com/forum/articles/7459/

  3. #3
    Join Date
    Sep 2009
    Location
    Targu Mures, Romania
    Posts
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multi-dimensional objects array

    You cannot allocate memory for multi-dimensional array like that,it is a bit more complicated.

    You could just use a Vector class which makes life easier:

    Qt Code:
    1. QVector<QVector<QTableWidgetItem*> > vector(10, QVector<QTableWidgetItem*>(10));
    2.  
    3. vector[2][3] = <YourPointerHere>
    To copy to clipboard, switch view to plain text mode 

    and also adds benefits like posibility to resize your array.

  4. The following user says thank you to csaken for this useful post:

    tuannp (23rd October 2011)

  5. #4
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multi-dimensional objects array

    thanks you so much!!!

Similar Threads

  1. QtScript: Passing an array of objects to C++
    By Plow in forum Qt Programming
    Replies: 0
    Last Post: 16th April 2010, 12:53
  2. use QVector as 2 dimensional Array
    By umulingu in forum Qt Programming
    Replies: 3
    Last Post: 1st January 2010, 12:31
  3. Replies: 0
    Last Post: 25th June 2008, 18:36
  4. Replies: 2
    Last Post: 16th April 2008, 10:31
  5. Multi Dimensional QList
    By aamer4yu in forum Qt Programming
    Replies: 5
    Last Post: 2nd April 2007, 06:46

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.