issue with nested qtabwidget with qvector<qtableview*> on the inner table
-
I have an application with a nested QTabWidget. the outer Tab-A, and Tab-B select different types of tableViews. the inner QTabWidgets inside of Tab-A and Tab-B are dynamic in tab count which is why I am using QVector<QTableView*> within each inner tab.
My functionality of selecting tabs on the inner QTabWidget works perfectly. my tableViews are all viewing as expected.When I switch the outer QTabWidget from Tab-A to Tab-b or visa-versa my application will crash.
the below snippet is what creates my inner tabs. there is a duplicate function for Tab-B when it is called.
QSqlTableModel *sourceModel = new QSqlTableModel( nullptr ); sourceModel->setTable( "tablename" ); QString filterString = "date = '" + date + "'"; sourceModel->setFilter( filterString ); sourceModel->select() ; CustomIdentityProxyModel *identityProxy = new CustomIdentityProxyModel(); identityProxy->setSourceModel( sourceModel ); QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(); proxyModel->setSourceModel( identityProxy ); QTableView* tableView = new QTableView( this ); tableView->setObjectName( date ); tableView->setModel( proxyModel ); tableView->setItemDelegate( m_customStyledItemDelegate ); m_tableViewInner_ATabs.append( tableView ); int tabIndex = ui->TabA_innerTab->addTab( tableView, date ); ui->TabA_innerTab->setCurrentIndex( tabIndex );
when switching outer tabs I recently added the follow snippet. before adding this snippet i got a "out of range" Not when switching it almost works. in that the tabs switch but are empty, and need to be re-selected to display the view. but when switching back again to the Tab-A it crashes on a segmentation fault.
void MainWindow::on_tabWidget_tabBarClicked( int index ) { switch ( index ) { case 0: for (int i = 0; i < m_tableViewInner_ATabs.size(); ++i) { QString tabName = m_tableViewInner_ATabs[i]->objectName(); ui->TabA_innerTab->addTab( m_tableViewInner_ATabs[i], tabName ); } break; case 1: for ( int i = 0; i < m_tableViewInner_BTabs.size(); ++i ) { QString tabName = m_tableViewInner_BTabs[i]->objectName(); ui->TabB_innerTab->addTab( m_tableViewInner_BTabs[i], tabName ); } break; } }
I hope my situation is understandable and that one of the many brainiacs out their has some insight for me.
thank you. -
Hi,
To be sure I understand, each time you switch you add new tabs with the same name and the same widget ?
Why not just build things once ? -
Did you check with the debugger what was happening ?
-
@SGaist when I do not to the addTab i get
ASSERT failure in QVector<T>::operator[]: "index out of range", file C:/msys64/mingw64/include/QtCore/qvector.h, line 462when I do addTab, I cant seem to determine where the segmentation fault occurs. indicating a highlight definition was not found.
All syntax definitions are up to date.Not sure if this tells you anything?
*running,thread-id="all"
~"[Thread 20288.0x4f48 exited with code 3221225725]\n"
[Thread 20288.0x4f48 exited with code 3221225725]
=thread-exited,id="2",group-id="i1"
Thread 2 in group i1 exited.
~"[Thread 20288.0x4f44 exited with code 3221225725]\n"
[Thread 20288.0x4f44 exited with code 3221225725]
=thread-exited,id="1",group-id="i1"
Thread 1 in group i1 exited.
~"[Thread 20288.0x4f4c exited with code 3221225725]\n"
[Thread 20288.0x4f4c exited with code 3221225725]
=thread-exited,id="3",group-id="i1"
Thread 3 in group i1 exited.
~"[Thread 20288.0x4f74 exited with code 3221225725]\n"
[Thread 20288.0x4f74 exited with code 3221225725]
=thread-exited,id="4",group-id="i1"
Thread 4 in group i1 exited.
~"[Thread 20288.0x4f78 exited with code 3221225725]\n"
[Thread 20288.0x4f78 exited with code 3221225725]
=thread-exited,id="5",group-id="i1"
Thread 5 in group i1 exited.
~"[Thread 20288.0x4f7c exited with code 3221225725]\n"
[Thread 20288.0x4f7c exited with code 3221225725]
=thread-exited,id="6",group-id="i1"
Thread 6 in group i1 exited.
~"[Thread 20288.0x4f80 exited with code 3221225725]\n"
[Thread 20288.0x4f80 exited with code 3221225725]
=thread-exited,id="7",group-id="i1"
Thread 7 in group i1 exited.
~"[Thread 20288.0x4f88 exited with code 3221225725]\n"
[Thread 20288.0x4f88 exited with code 3221225725]
=thread-exited,id="9",group-id="i1"
Thread 9 in group i1 exited.
~"[Thread 20288.0x4f8c exited with code 3221225725]\n"
[Thread 20288.0x4f8c exited with code 3221225725]
=thread-exited,id="10",group-id="i1"
Thread 10 in group i1 exited.
~"[Thread 20288.0x4f90 exited with code 3221225725]\n"
[Thread 20288.0x4f90 exited with code 3221225725]
=thread-exited,id="11",group-id="i1"
Thread 11 in group i1 exited.
~"[Thread 20288.0x4f94 exited with code 3221225725]\n"
[Thread 20288.0x4f94 exited with code 3221225725]
=thread-exited,id="12",group-id="i1"
Thread 12 in group i1 exited.
~"[Thread 20288.0x4f84 exited with code 3221225725]\n"
[Thread 20288.0x4f84 exited with code 3221225725]
=thread-exited,id="8",group-id="i1"
Thread 8 in group i1 exited.
=thread-exited,id="13",group-id="i1"
Thread 13 in group i1 exited.
~"\nProgram terminated with signal "
~"SIGSEGV, Segmentation fault.\n" -
As @SGaist said, can you run this in the debugger and inspect the call stack, when the crash happens?