Solved QStackedWidget (index out of range)
-
@mrjj this UI containing QCustomPlot and Graph works fine, but gives an error when I add it to QStackedWidget. How can it possibly be evaluated?
-
@ahsan737
Are you sure its not empty and you connected signals to some slot so it tried to do something ?
Try adding a new QCustomPlot instead and see.ui->stackedWidget->addWidget(new QCustomPlot (this) );
to see if that also gives same error.
-
@ahsan737 said in QStackedWidget (index out of range):
Move to next Index
Did you actually check what @JonB wrote?
Can you post the complete backtrace? -
Hi,
void MainWindow::_onNext()
{
int Index=ui->stackedWidget->currentIndex();
Index++;
ui->stackedWidget->setCurrentIndex(Index);
}You are missing the boundary check so suggested by @JonB.
-
Hi
I'm not sure the stackedwidget in itself is to blame for the index out of range.
If i do this
ui->stackedWidget->setCurrentIndex(1000);
in a blank GUI project. Nothing is shown and app just starts.
Also in the inner code, the index is checked.QWidget *QStackedLayout::widget(int index) const { Q_D(const QStackedLayout); if (index < 0 || index >= d->list.size()) return nullptr; return d->list.at(index)->widget(); }
-
@mrjj Exactly what I was double checking :-)
-
@SGaist
Hi
I recalled having a off by one error with a stackedwidget and it seemed to just ignore it - back then so felt the urge to use the source.To Make it more interesting, QCustomPlot seems to be using a QVector but
the actual error is
ASSERT failure in QList<T>So I guess this calls for a back trace as Christian is after :)
-
@mrjj said in QStackedWidget (index out of range):
So I guess this calls for a back trace as Christian is after :)
Agreed
-
Thanks a lot, for your dedicated and kind response, the issue is resolved. It was being caused because the application was failing to read the initial configuration file as I mistakenly forgot calling a class in the startup. Silly yet frustrating mistake,
-
@ahsan737
Good you found it.
So the QList it had the error about was one of the widget that you inserted into the stacked so it seemed it was related to that ? -
@mrjj yes, error was related to QList which was a part of the widget. and when I try to add that widget to stack then it makes the app crash.