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. -
@Axel-Spoerl
this is the call stack when I do not addTab which is how it should be working. from my understanding.1 RaiseFailFastException 0x7fff2a87b2dc
2 qt_message_fatal qlogging.cpp 1905 0x7fff00f93051
3 QMessageLogger::fatal qlogging.cpp 893 0x7fff012a9038
4 qt_assert_x qglobal.cpp 3366 0x7fff012a8c17
5 QVector<QTableView *>::operator[] qvector.h 462 0x7ff6189f5048
6 MainWindow::on_systemLogHeaderSectionResized mainwindow.cpp 1686 0x7ff6189d9166
7 QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1, 2>, QtPrivate::List<int, int, int>, void, void (MainWindow:: *)(int, int, int)>::call qobjectdefs_impl.h 152 0x7ff6189f5623
8 QtPrivate::FunctionPointer<void (MainWindow:: *)(int, int, int)>::call<QtPrivate::List<int, int, int>, void> qobjectdefs_impl.h 185 0x7ff6189f5d2f
9 QtPrivate::QSlotObject<void (MainWindow:: *)(int, int, int), QtPrivate::List<int, int, int>, void>::impl qobjectdefs_impl.h 418 0x7ff6189f5988
10 QtPrivate::QSlotObjectBase::call qobjectdefs_impl.h 398 0x7fff0124f1cc
11 doActivate<false> qobject.cpp 3886 0x7fff0124f1cc
12 QMetaObject::activate qobject.cpp 3946 0x7fff01195d47
13 QHeaderView::sectionResized moc_qheaderview.cpp 455 0x7ffeffc3ade0
14 QHeaderViewPrivate::resizeSections qheaderview.cpp 3600 0x7ffeffc3ade0
15 QHeaderView::viewportEvent qheaderview.cpp 2816 0x7ffeffc422c2
16 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1189 0x7fff01163bdc
17 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1194 0x7fff01164819
18 QApplicationPrivate::notify_helper qapplication.cpp 3626 0x7ffeff9d7fc2
19 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1063 0x7fff011651e0
20 QCoreApplication::sendEvent qcoreapplication.cpp 1458 0x7fff011651e0
... <More>@swankster Thank you guys, tracking it through stack view. i found the issue. Tab position starts at 0. i was missing a -1 in a reference position.
thanks again for the direction -
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?
-
@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"@swankster disregard the previous. this was the first segmentation fault picked up.
--- token barrier ---
dNOTE: INFERIOR RUN REQUESTED
Run requested...
dState changed from InferiorStopOk(11) to InferiorRunRequested(7)
Running requested...
<66-exec-continue66^running
dNOTE: INFERIOR RUN OK
Running.
dState changed from InferiorRunRequested(7) to InferiorRunOk(8)
*running,thread-id="all"~"\nThread "
~"1 received signal SIGSEGV, Segmentation fault.\n"
~"0x00007ffeebdcec7a in ntdll!RtlGetFullPathName_UstrEx () from C:\WINDOWS\SYSTEM32\ntdll.dll\n"
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",frame={addr="0x00007ffeebdcec7a",func="ntdll!RtlGetFullPathName_UstrEx",args=[],from="C:\WINDOWS\SYSTEM32\ntdll.dll",arch="i386:x86-64"},thread-id="1",stopped-threads="all"
dNOTE: INFERIOR SPONTANEOUS STOP
Stopped.
dState changed from InferiorRunOk(8) to InferiorStopOk(11)
dHANDLING SIGNAL SIGSEGV
Stopped: Segmentation fault (Signal SIGSEGV). -
@swankster disregard the previous. this was the first segmentation fault picked up.
--- token barrier ---
dNOTE: INFERIOR RUN REQUESTED
Run requested...
dState changed from InferiorStopOk(11) to InferiorRunRequested(7)
Running requested...
<66-exec-continue66^running
dNOTE: INFERIOR RUN OK
Running.
dState changed from InferiorRunRequested(7) to InferiorRunOk(8)
*running,thread-id="all"~"\nThread "
~"1 received signal SIGSEGV, Segmentation fault.\n"
~"0x00007ffeebdcec7a in ntdll!RtlGetFullPathName_UstrEx () from C:\WINDOWS\SYSTEM32\ntdll.dll\n"
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",frame={addr="0x00007ffeebdcec7a",func="ntdll!RtlGetFullPathName_UstrEx",args=[],from="C:\WINDOWS\SYSTEM32\ntdll.dll",arch="i386:x86-64"},thread-id="1",stopped-threads="all"
dNOTE: INFERIOR SPONTANEOUS STOP
Stopped.
dState changed from InferiorRunOk(8) to InferiorStopOk(11)
dHANDLING SIGNAL SIGSEGV
Stopped: Segmentation fault (Signal SIGSEGV).@swankster
As @SGaist & @Axel-Spoerl have said, you need to run your program inside a debugger and show the stack trace when it crashes. -
As @SGaist said, can you run this in the debugger and inspect the call stack, when the crash happens?
@Axel-Spoerl
this is the call stack when I do not addTab which is how it should be working. from my understanding.1 RaiseFailFastException 0x7fff2a87b2dc
2 qt_message_fatal qlogging.cpp 1905 0x7fff00f93051
3 QMessageLogger::fatal qlogging.cpp 893 0x7fff012a9038
4 qt_assert_x qglobal.cpp 3366 0x7fff012a8c17
5 QVector<QTableView *>::operator[] qvector.h 462 0x7ff6189f5048
6 MainWindow::on_systemLogHeaderSectionResized mainwindow.cpp 1686 0x7ff6189d9166
7 QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1, 2>, QtPrivate::List<int, int, int>, void, void (MainWindow:: *)(int, int, int)>::call qobjectdefs_impl.h 152 0x7ff6189f5623
8 QtPrivate::FunctionPointer<void (MainWindow:: *)(int, int, int)>::call<QtPrivate::List<int, int, int>, void> qobjectdefs_impl.h 185 0x7ff6189f5d2f
9 QtPrivate::QSlotObject<void (MainWindow:: *)(int, int, int), QtPrivate::List<int, int, int>, void>::impl qobjectdefs_impl.h 418 0x7ff6189f5988
10 QtPrivate::QSlotObjectBase::call qobjectdefs_impl.h 398 0x7fff0124f1cc
11 doActivate<false> qobject.cpp 3886 0x7fff0124f1cc
12 QMetaObject::activate qobject.cpp 3946 0x7fff01195d47
13 QHeaderView::sectionResized moc_qheaderview.cpp 455 0x7ffeffc3ade0
14 QHeaderViewPrivate::resizeSections qheaderview.cpp 3600 0x7ffeffc3ade0
15 QHeaderView::viewportEvent qheaderview.cpp 2816 0x7ffeffc422c2
16 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1189 0x7fff01163bdc
17 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1194 0x7fff01164819
18 QApplicationPrivate::notify_helper qapplication.cpp 3626 0x7ffeff9d7fc2
19 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1063 0x7fff011651e0
20 QCoreApplication::sendEvent qcoreapplication.cpp 1458 0x7fff011651e0
... <More> -
@Axel-Spoerl
this is the call stack when I do not addTab which is how it should be working. from my understanding.1 RaiseFailFastException 0x7fff2a87b2dc
2 qt_message_fatal qlogging.cpp 1905 0x7fff00f93051
3 QMessageLogger::fatal qlogging.cpp 893 0x7fff012a9038
4 qt_assert_x qglobal.cpp 3366 0x7fff012a8c17
5 QVector<QTableView *>::operator[] qvector.h 462 0x7ff6189f5048
6 MainWindow::on_systemLogHeaderSectionResized mainwindow.cpp 1686 0x7ff6189d9166
7 QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1, 2>, QtPrivate::List<int, int, int>, void, void (MainWindow:: *)(int, int, int)>::call qobjectdefs_impl.h 152 0x7ff6189f5623
8 QtPrivate::FunctionPointer<void (MainWindow:: *)(int, int, int)>::call<QtPrivate::List<int, int, int>, void> qobjectdefs_impl.h 185 0x7ff6189f5d2f
9 QtPrivate::QSlotObject<void (MainWindow:: *)(int, int, int), QtPrivate::List<int, int, int>, void>::impl qobjectdefs_impl.h 418 0x7ff6189f5988
10 QtPrivate::QSlotObjectBase::call qobjectdefs_impl.h 398 0x7fff0124f1cc
11 doActivate<false> qobject.cpp 3886 0x7fff0124f1cc
12 QMetaObject::activate qobject.cpp 3946 0x7fff01195d47
13 QHeaderView::sectionResized moc_qheaderview.cpp 455 0x7ffeffc3ade0
14 QHeaderViewPrivate::resizeSections qheaderview.cpp 3600 0x7ffeffc3ade0
15 QHeaderView::viewportEvent qheaderview.cpp 2816 0x7ffeffc422c2
16 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1189 0x7fff01163bdc
17 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1194 0x7fff01164819
18 QApplicationPrivate::notify_helper qapplication.cpp 3626 0x7ffeff9d7fc2
19 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1063 0x7fff011651e0
20 QCoreApplication::sendEvent qcoreapplication.cpp 1458 0x7fff011651e0
... <More>@swankster said in issue with nested qtabwidget with qvector<qtableview*> on the inner table:
5 QVector<QTableView *>::operator[] qvector.h 462 0x7ff6189f5048
This, and your earlier
ASSERT failure in QVector<T>::operator[]: "index out of range", file C:/msys64/mingw64/include/QtCore/qvector.h, line 462
would suggest to me the
QVector<QTableView *>
you talk about is not of the size expected at some point. @Axel-Spoerl or @SGaist might be able to guess something, for my part I would want to see a minimal reproducible example of your full code to get further.Have you tried removing all the model data, proxies, SQL code to start with, why should that be relevant to your switching of tabs holding tableviews, whatever the issue proves to be? If it's a UI issue the backed data should not matter. Though it's interesting the stack shows it's failing during a
QHeaderView
resize.MainWindow::on_systemLogHeaderSectionResized()
is yours, and is accessing theQVector<QTableView *>
out of range? Show what you are indexing it by and what its current size is?A complete minimal example might be less than 100 lines of code.
-
@Axel-Spoerl
this is the call stack when I do not addTab which is how it should be working. from my understanding.1 RaiseFailFastException 0x7fff2a87b2dc
2 qt_message_fatal qlogging.cpp 1905 0x7fff00f93051
3 QMessageLogger::fatal qlogging.cpp 893 0x7fff012a9038
4 qt_assert_x qglobal.cpp 3366 0x7fff012a8c17
5 QVector<QTableView *>::operator[] qvector.h 462 0x7ff6189f5048
6 MainWindow::on_systemLogHeaderSectionResized mainwindow.cpp 1686 0x7ff6189d9166
7 QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1, 2>, QtPrivate::List<int, int, int>, void, void (MainWindow:: *)(int, int, int)>::call qobjectdefs_impl.h 152 0x7ff6189f5623
8 QtPrivate::FunctionPointer<void (MainWindow:: *)(int, int, int)>::call<QtPrivate::List<int, int, int>, void> qobjectdefs_impl.h 185 0x7ff6189f5d2f
9 QtPrivate::QSlotObject<void (MainWindow:: *)(int, int, int), QtPrivate::List<int, int, int>, void>::impl qobjectdefs_impl.h 418 0x7ff6189f5988
10 QtPrivate::QSlotObjectBase::call qobjectdefs_impl.h 398 0x7fff0124f1cc
11 doActivate<false> qobject.cpp 3886 0x7fff0124f1cc
12 QMetaObject::activate qobject.cpp 3946 0x7fff01195d47
13 QHeaderView::sectionResized moc_qheaderview.cpp 455 0x7ffeffc3ade0
14 QHeaderViewPrivate::resizeSections qheaderview.cpp 3600 0x7ffeffc3ade0
15 QHeaderView::viewportEvent qheaderview.cpp 2816 0x7ffeffc422c2
16 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1189 0x7fff01163bdc
17 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1194 0x7fff01164819
18 QApplicationPrivate::notify_helper qapplication.cpp 3626 0x7ffeff9d7fc2
19 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1063 0x7fff011651e0
20 QCoreApplication::sendEvent qcoreapplication.cpp 1458 0x7fff011651e0
... <More>@swankster Thank you guys, tracking it through stack view. i found the issue. Tab position starts at 0. i was missing a -1 in a reference position.
thanks again for the direction -
Great !
Since you have it working now please mark the thread as solved using the "Topic Tools" button or the three dotted button beside the answer you deem correct so that other forum members may know a solution has been found :-) -