Results 1 to 7 of 7

Thread: Can QVector hold objects?

  1. #1
    Join Date
    Aug 2009
    Location
    United States
    Posts
    45
    Thanks
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Can QVector hold objects?

    Maybe I'm just doing something wrong, but when I try to create a QVector that holds a type of objects I get a whole slew of errors. Can a QVector hold objects, like in in standard C++?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can QVector hold objects?

    Yes, why not ?
    What errors are you getting ? Without knowing the error we cant say anything.

  3. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can QVector hold objects?

    Hi, you won't be able to store an object of an QObject derived class because those classes do not implement the = operator. Only assignable classes can be stored in QVector.

    Ginsengelf

  4. #4
    Join Date
    Aug 2009
    Location
    United States
    Posts
    45
    Thanks
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can QVector hold objects?

    It is a custom class I was wanting to store. You're saying this isn't possible, right?

    In a non-Qt C++ program I defined the class as:

    Qt Code:
    1. class point{
    2. public:
    3. point();
    4. double lX; // Local x&y
    5. double lY;
    6. double gX; // global x&y
    7. double gY;
    8. };
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Can QVector hold objects?

    It should work without problems. What is the first error message you get?

  6. #6
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Can QVector hold objects?

    You have to store them as pointers.

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

    Default Re: Can QVector hold objects?

    Quote Originally Posted by boudie View Post
    You have to store them as pointers.
    No, he doesn't. They are not derived from QObject.

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

    N3wb (17th April 2010)

Similar Threads

  1. checkable QAction shortcut hold
    By winder in forum Qt Programming
    Replies: 7
    Last Post: 18th February 2010, 16:48
  2. Replies: 3
    Last Post: 9th January 2010, 16:47
  3. QTextEdit does not hold Object Id behind
    By validator in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2008, 01:25
  4. Qvector
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2007, 11:46
  5. Replies: 7
    Last Post: 18th July 2006, 22:33

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.