Solved ui->addTab "index out of range" !?
-
Then you already have a debugger. Just start your application in debug mode, make it crash and you'll have the stack trace.
-
@SGaist
There is nothing under Stack when I am debugging...
Are my settings wrong? I can't find anything wrong.
Also nothing under Breakpoints, Threads, Modules, Source Files, Snapshots and Registers.
Only the Debugger Log shows content -
Silly question but are you starting the application as usual or are you starting it with the other button which means "debug the application" ?
-
@SGaist
No, I click Start Debugging
(but as I see now, there is Output in Modules tab when I am not closing the error message but it doesn't matter I think) -
@SGaist
UPDATE
Ok now I know, there are two points in my function, where the program crashes.
My function:GraphWidget *newGraphWidget = new GraphWidget(this); graphWidgets.append(newGraphWidget); QString name = "tab " + QString::number(tabCounter); qDebug() << ui->Graph->currentIndex(); //ui->Graph->addTab(newGraphWidget, "title"); // !? PROBLEM !? qDebug() << ui->Graph->currentIndex(); tabCounter += 1; QVBoxLayout *vBoxLayout = new QVBoxLayout(); vBoxLayout->setAlignment(Qt::AlignTop); QWidget *allNodesWidget = new QWidget(); allNodesWidget->setLayout(vBoxLayout); //ui->allNodes_scrollArea->setWidget( allNodesWidgets[ui->Graph->currentIndex()] ); // !? PROBLEM !? allNodesWidgets.append(allNodesWidget);
The two lines where I commented !? PROBLEM !? are the two lines. If I uncomment one of these, the program crashes with the Index error. (UPDATE: the second one is because ui->Graph->currentIndex() is -1)
I have really no Idea what this means...
Help please! -
What is the initial value of tabCounter? What is the vector size?
-
This post is deleted! -
allNodesWidgets[ui->Graph->currentIndex()]
ui->Graph->currentIndex()
is almost certainly out of bounds -
@VRonin
Oh, yes you are right, thanks.
But it unfortunately does not solve teh actual problem :/ -
@Vinod-Kuntoji
The initial value of TabCounter is 0.
The vector has no specific size, it gets bigger when I add new items... what exactely do you mean? -
@Niagarer when you add new tab it do not mean that current index will be changed
-
@Paul-Busovikov
Yes...?
To get sure I wroteqDebug() << ui->Graph->currentIndex();
before and after adding a new tab
-
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.