Results 1 to 5 of 5

Thread: How to insert a value of a Qlist inside of another Qlist

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to insert a value of a Qlist inside of another Qlist

    In line 13 in your original code, you declare a QList named "orderlist". This is an empty list. In line 17, you try to access the item at index "i" in this list. Because the list is empty, there is no item at -any- index (including zero), so you get an out of range error.

    Did you make a mistake and declare this "orderlist" as a local variable, and thereby maybe hide a member variable in your class with the same name that actually does have contents?

    In any case, you should also follow anda_skoa's suggestion to use "orderlist.count()" as the terminator for your loop variable instead of a hard-coded "3".

    Also, your loops over i and j don't make a lot of sense. You are executing the innermost loop 9 times (3 times 3 for i * j), but you are only doing something if i == j. You can get rid of the inner loop entirely, and move its code into the loop over i. Replace j with i and you get the same result.
    Last edited by d_stranz; 9th August 2019 at 17:03.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    ofbrc (6th September 2019)

Similar Threads

  1. clear qlist inside qmap
    By franki in forum Newbie
    Replies: 3
    Last Post: 16th December 2013, 13:17
  2. Replies: 3
    Last Post: 10th February 2012, 11:17
  3. Cast QList<Foo*> to QList<const Foo*>
    By vfernandez in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2010, 16:04
  4. Replies: 4
    Last Post: 20th August 2010, 13:54
  5. QList inside a QList
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 1st July 2009, 11:59

Tags for this Thread

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.