Good evening!
What is wrong with the following code? I'm trying to use "insertPattern" method to return a QVector<Number>("Number" is an object i created) to "patternList". Then, push_back it into a QList. I'm not getting any compilation error message, but when i run it i get that error!
QList<QVector<Number>> RegNumber::patternList(QList<QVector<Number>> pl, int array[], int sizeArray)
// Irrelevant code here.
for(...) {//If i delete this "for" and call "insertPattern" one time, the program runs fine.
// Irrelevant code here.
pl.push_back( insertPattern(array, sizeArray) );
}
QVector<Number> RegNumber::insertPattern(int array[], int sizeArray)
{
QVector<Number> pattern;
pattern.push_back( Number(0, 1) );
for(int i = 0; i < sizeArray; i++)
{
if(array[i] != 0)
pattern.push_back( Number((i + 2), array[i]) ) ;
}
return pattern;
}
QList<QVector<Number>> RegNumber::patternList(QList<QVector<Number>> pl, int array[], int sizeArray)
// Irrelevant code here.
for(...) {//If i delete this "for" and call "insertPattern" one time, the program runs fine.
// Irrelevant code here.
pl.push_back( insertPattern(array, sizeArray) );
}
QVector<Number> RegNumber::insertPattern(int array[], int sizeArray)
{
QVector<Number> pattern;
pattern.push_back( Number(0, 1) );
for(int i = 0; i < sizeArray; i++)
{
if(array[i] != 0)
pattern.push_back( Number((i + 2), array[i]) ) ;
}
return pattern;
}
To copy to clipboard, switch view to plain text mode
ASSERT failure in QVector(T):
perator[]: "index out of range", file C:\Qt\5.4\mingw491_32\include\QtCore/qvector.h, line 396
How can i fix it?
Bookmarks