Greetings. I develop draggable tabs like browsers. Here is the mouseMoveEvent code for my custom QTabBar :
void MagicTabBar::mouseMoveEvent(QMouseEvent *e){ if(this->count() > 1){//если вкладок больше одной QRect r = this->parentWidget()->geometry(); r.setHeight(this->rect().height()); if(r.contains(e->globalPos())){ //проверка находится ли курсор мыши внутри QTabBar QTabBar::mouseMoveEvent(e); } else{// Если перетянули вкладку за границы QTabBar, она стала окном MagicTabWidget* mtw = new MagicTabWidget; qobject_cast<MagicTabBar*>(mtw->tabBar())->Position = (this->Position+this->window()->pos())-mapToGlobal(tabRect(this->currentIndex()).topLeft()); this->releaseMouse(); mtw->resize(this->parentWidget()->size()); mtw->addTab(qobject_cast<QTabWidget*>(this->parentWidget())->currentWidget(),tabText(this->currentIndex())); // ERROR HERE! mtw->show(); mtw->tabBar()->grabMouse(); } } else{ //если вкладка одна, то просто двигаем окно this->window()->move(e->globalPos()-Position); } } MagicTabBar and MagicTabWidget are my classes inherited from QTabBar , QTabWidget respectively. The program crashes in a very curious way. If the tab is slow, then everything is fine. But if you dramatically pull it out of the QTabBar , a Debug error! Program:QtCored.dll File: global/qglobal.cpp ASSERT failure in QList<T>::operator[] "index out of range", file qlist.h, line 545 thrown Debug error! Program:QtCored.dll File: global/qglobal.cpp ASSERT failure in QList<T>::operator[] "index out of range", file qlist.h, line 545 Debug error! Program:QtCored.dll File: global/qglobal.cpp ASSERT failure in QList<T>::operator[] "index out of range", file qlist.h, line 545 . With that, I don’t use QList anywhere. The cause of the error is the line next to which the comment "ERROR". What could be wrong in it? And why does it work when you pull a tab slowly, and if not quickly?
qobject_cast<QTabWidget*>(this->parentWidget())->currentWidget(). ParentWidget in this case isQTabWidget. - Nik