Results 1 to 3 of 3

Thread: Array error: Don't know how to fix it.

  1. #1
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Array error: Don't know how to fix it.

    Hi!

    I would like to know why the following code shows me an error message when i run my program. I have no compile error message, just when i start the program. I commented some line to you understand better the code.

    Qt Code:
    1. QList<QVector<Number> > Game::dozensSeqDrawn(int tm) {
    2. int acum, ini, aux[size]; // size is 1786
    3. ini = setStartRead( tm ); // sets a start point to read the matrix
    4. QList<QVector<Number>> pl; //Number has (int val, int acum) as attributes
    5.  
    6. for(int dz = 0; dz < 6; dz++) {
    7. arrayResetZero(aux, size); // sets to 0 each cell in the array
    8. acum = 0;
    9.  
    10. for(int i = ini; i < size; i++) {
    11.  
    12. if( dozenInArray(historic[i], dz) ) {//historic[i] is a qvector
    13. acum++;
    14. }
    15. else if(acum > 0) {
    16. aux[(acum - 1)] += 1;
    17. acum = 0;
    18. }
    19.  
    20. }
    21.  
    22. pl.push_back( seqDrawnVector(aux, size) );
    23. }
    24.  
    25. return pl;
    26. }
    27.  
    28. QVector<Number> Game::seqDrawnVector(int array[], int length) {
    29. QVector<Number> list;
    30.  
    31. for(int i = 0; i < length; i++)
    32. if(array[i] != 0)
    33. list.push_back( Number((i + 1), array[i]) );
    34.  
    35. return list;
    36. }
    To copy to clipboard, switch view to plain text mode 

    ASSERT failure in QList<T>:: operator[]: "index out of range", file /usr/include/qt/QtCore/qlist.h, line 518
    Aborted (core dumped)
    I tried to change a little bit my code to this:
    Qt Code:
    1. QList<QVector<Number> > Game::dozensSeqDrawn(int tm) {
    2. QList<QVector<Number>> pl; //Number has (int val, int acum) as attributes
    3. QVector<Number> line;
    4.  
    5. line.push_back(Number(-1, -1));
    6. line.push_back(Number(-1, -1));
    7. line.push_back(Number(-1, -1));
    8.  
    9. pl.push_back( line );
    10.  
    11. return pl;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Same error message.
    Last edited by robgeek; 3rd February 2016 at 23:55.

  2. #2
    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: Array error: Don't know how to fix it.

    I don't see anything in the code you post here that could cause that error. You only push things onto an empty list, you never read it, at least not in the posted code. Your error comes from someplace else in your code, most likely.

    Have you correctly initialized whatever variable you are using to index into the list? Do you set it to less than zero or greater than the list range somewhere? Is your list ever empty when you try to read from it?

    Do you know how to use the debugger? Run it with a debug version of your program and see where it fails.

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

    robgeek (4th February 2016)

  4. #3
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: Array error: Don't know how to fix it.

    Thanks for your answer! I'll try qdebugger. I'll post results here later.

Similar Threads

  1. How to parse nested JSON Array and Object inside array
    By Radhika in forum General Programming
    Replies: 5
    Last Post: 17th December 2015, 08:42
  2. How to catch out of range array crashed error?
    By binary001 in forum Newbie
    Replies: 1
    Last Post: 10th October 2015, 18:12
  3. Replies: 0
    Last Post: 9th August 2011, 10:15
  4. Replies: 2
    Last Post: 12th November 2010, 14:42
  5. declare an array of QSemaphore and array of slot functions
    By radeberger in forum Qt Programming
    Replies: 11
    Last Post: 2nd May 2010, 13:24

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.