Results 1 to 4 of 4

Thread: QVector<QVector3D> index out of range at pushback operation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2018
    Posts
    30
    Thanks
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default QVector<QVector3D> index out of range at pushback operation

    I have this typeof data:
    Qt Code:
    1. QVector<QVector3D> vector_aux;
    2. QVector<int> indicies;
    3. QVector<QVector3D> vector_coord;
    To copy to clipboard, switch view to plain text mode 

    My goal is to rearrange the vector_aux to vector_coord by the value stored in indicies.

    If i store my singular data in vector_aux like this no error occured:
    Qt Code:
    1. vector_aux << QVector3D( 0.276388, 0.850649, -0.447220)
    2. << QVector3D( 0.483971, 0.716565, -0.502302) .. and so on till i store 104 data.
    To copy to clipboard, switch view to plain text mode 

    The indicies.lenght() => 548

    If i try do it and when i stored 500 data the program crash:
    ..
    Ok at = 490
    Ok at = 500
    ASSERT failure in QVector<T>:: operator[]: "index out of range", file C:\Qt\Qt5.13.1\5.13.1\mingw73_64\include/QtCore/qvector.h, line 448

    Qt Code:
    1. for (int i=0; i<indicies.length(); i++){
    2. vector_coord.push_back(vector_aux[indicies[i]]);
    3. if (i%10==0){
    4. qDebug() << "Ok at =" << i;
    5. }
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    There is a limit of 500 data that i can store, or there an other reason for my trouble?
    Last edited by andreaQt; 4th September 2020 at 17:56.

  2. #2
    Join Date
    Sep 2020
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QVector<QVector3D> index out of range at pushback operation

    Apparently one of your values in "indicies" is larger or equal vector_aux.length().
    According to your printout, you should inspect the values of "indicies" in the range 501 to 510.

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

    andreaQt (21st September 2020)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,720
    Thanks
    259
    Thanked 760 Times in 750 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QVector<QVector3D> index out of range at pushback operation

    Put a qDebug statement at the top of your for() loop

    Qt Code:
    1. for (int i=0; i<indicies.length(); i++){
    2. qDebug() << i << indices[i];
    To copy to clipboard, switch view to plain text mode 

    (before you try to access vector_aux), and you'll probably discover that "indices" does not contain the values you think it should.

    .. and so on till i store 104 data.
    Anyway, if vector_aux has only 104 QVector3D items in it, why is indices 548 entries long? And why do you try to push 548 items onto vector_coord when you have only 104 coordinates to start with?
    <=== 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.

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

    andreaQt (21st September 2020)

  6. #4
    Join Date
    Mar 2018
    Posts
    30
    Thanks
    18
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QVector<QVector3D> index out of range at pushback operation

    yes, my mistake in my code is that one/more value stored in indicies is out or equal vector_aux.length()

    i'm trying to extract data from file generated on blender in format -> blender.obj

Similar Threads

  1. Replies: 5
    Last Post: 13th May 2015, 17:18
  2. Replies: 0
    Last Post: 9th January 2015, 11:09
  3. What's the fastest QVector operation
    By Momergil in forum Qt Programming
    Replies: 5
    Last Post: 30th May 2014, 17:22
  4. best way to delete QVector<QVector3D>
    By saman_artorious in forum Qt Programming
    Replies: 11
    Last Post: 4th July 2013, 09:11
  5. Replies: 0
    Last Post: 22nd June 2013, 11:02

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.