Solved ui->addTab "index out of range" !?
-
@Paul-Busovikov
Oh yes, I see, I'm sorry. -
@mrjj
Yep, it works
Yes, I duplicated an old project. And now the MainWindow sould create a new tab in the tab widget called Graph with an object of my class GraphWidget (QGraphicsView). Nothing else (in the constructor). -
Ok, all good then (with your Qt) :)
It should be no different inserting a QGraphicsView subclass -
@mrjj
I'm not sure if I understood that correctly...
In the old project GraphWidget is just a normal Widget. Here it is a QGraphicsView. Where is the mattering difference? -
Its not. 100% the same.
class QGraphicsView : public QAbstractScrollArea
class QAbstractScrollArea : public QFrame
class QFrame : public QWidget -
@mrjj
Ok... So it is because of the QGraphicsView
And what could I do to fix that? -
@Niagarer here I see that you add your Widget to vector after you are trying to get one from
//ui->allNodes_scrollArea->setWidget( allNodesWidgets[ui->Graph->currentIndex()] ); // !? PROBLEM !? allNodesWidgets.append(allNodesWidget);
-
@Niagarer
No, its not due to QGraphicsView.
its something else. -
@mrjj
Ok >.<
can you give me suggestions what else I could try? -
Im not really sure "what is not working".
You seem to crash your list when no tab is active
ui->Graph->currentIndex() returns -1 in this case.Other than that im not sure what you ask?
-
@mrjj
No, yes the list thing was a mistake but the actual problem is still that In this project I event can not do this:ui->Graph->addTab(new QPushButton("blobb"),"tab");
And I have no idea why
And exactely this is the line where it crashes
When I do this:qDebug() << "first"; ui->Graph->addTab(new QPushButton("blobb"),"tab"); qDebug() << "second";
I get is this:
first ASSERT failure in QVector<T>::operator[]: "index out of range"
-
Is ui->Graph the tabWidget ?
You do call setupUI() in (mainwin) constructor ? to setup ui before use?Also addTab is the build in func? you did NOT add a new function your self?
-
@mrjj
Yes, the constructor of MainWindow now looks like this:MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { qDebug() << "Start of MainWindow Constructor"; ui->setupUi(this); tabCounter = 0; qDebug() << "first"; ui->Graph->addTab(new QPushButton("blobb"),"tab"); qDebug() << "second"; qDebug() << "End of MainWindow Constructor"; }
No I did not build a new addTab()-function
Yes the ui->Graph is the TabGidget -
@Niagarer
Really strange then.
All seems ok.If you zip and upload project , I can try and see if it crash here
-
@mrjj
Ok, thank you. Give me a minute -
-
@Niagarer
Super. Found itWhen you insert new tab. A signal is sent (currentChanged)
you catch signal ( its auto connected )
on_Graph_currentChanged(int index)
and then kill yourself with allNodesWidgets[index] as index is 100% surely out of bounds as nothing added to
allNodesWidgets yet.void MainWindow::on_Graph_currentChanged(int index)
{
ui->allNodes_scrollArea->setWidget( allNodesWidgets[index] ); <<<< this gives the actual error
} -
@mrjj
Pheww...
Yes, you are right, now it works.
Thanks A LOT man!
Now I can sleep again... >.< -
@Niagarer
:)
Super.
It took 10 secs with breakpoint to find.
If larger program, it would been one of the nasty ones. :)Good sleep then ;)