Solved ui->addTab "index out of range" !?
-
To make it easier:
the lineui->Graph->addTab(new QWidget(this), "hello");
does not work. Doesn't matter where I call it.
-
@Niagarer
a QWidget is not really visible. (it paints nothing)
Try with other type -
@mrjj
Ok.
This also does not work:GraphWidget *newGraphWidget = new GraphWidget(this); //GraphWidget is a QGraphicsView ui->Graph->addTab(newGraphWidget, "hello");
-
@Niagarer
this works here
ui->tabWidget->addTab( new QPushButton("kkk") ,"tab" );
-
@mrjj
It doesn't work in my Program... xD
What the hell...
-
@Niagarer yes it doesn't
int index = 0; for (int i = 0; i < 10; ++i ) { index = ui->tabWidget->addTab( new QWidget, "title" ); qDebug() << index << " " << ui->tabWidget->currentIndex() ; }
0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0
-
Hi
I assume you are doing other stuff in your app since it crashes.Just to be sure, your Qt is not sick.
Can you try test project
https://www.dropbox.com/s/tpyxmww5t98i4um/untitled39.zip?dl=0 -
@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