Results 1 to 2 of 2

Thread: Fill QList<MyOwnClass>

  1. #1
    Join Date
    Jul 2014
    Posts
    17
    Thanks
    1

    Default Fill QList<MyOwnClass>

    Hi,
    i want to fill QList with my own Class, but I don't know, when i have to use the "*".


    Qt Code:
    1. List<MyOwnClass> *myList = new List<MyOwnClass>;
    2.  
    3. MyOwnClass *oneItem = new MyOwnClass;
    4. oneItem.P1 = "firstMember";
    5.  
    6. myList->append(oneItem);
    To copy to clipboard, switch view to plain text mode 


    My Error say's something like:

    error: no matching function for call to 'QList<MyOwnClass>::append(MyOwnClass*&)'
    myList->append(oneItem);


    Can anybody help?

    ^
    ^

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Fill QList<MyOwnClass>

    Your QList is declared to contain instances of MyOwnClass and you are trying to append a pointer-to-MyOwnClass. These are not the same thing, hence the error.

    Assuming your class can be copied:
    Qt Code:
    1. QList<MyOwnClass> list;
    2. MyOwnClass a;
    3. list.append(a);
    To copy to clipboard, switch view to plain text mode 
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. Replies: 2
    Last Post: 8th May 2014, 09:28
  2. how to fill Qlist in minimum time
    By shivendra46d in forum Newbie
    Replies: 2
    Last Post: 26th August 2013, 12:08
  3. Replies: 1
    Last Post: 9th May 2011, 15:19
  4. How to fill a QList<struct> ?
    By falconium in forum Newbie
    Replies: 1
    Last Post: 1st March 2011, 21:59
  5. Replies: 4
    Last Post: 20th August 2010, 13:54

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.