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?

  • use the debugger - Abyx
  • @Abyx so I already know for sure that the error is here: qobject_cast<QTabWidget*>(this->parentWidget())->currentWidget() . ParentWidget in this case is QTabWidget . - Nik
  • What version of qt? - strangeqargo
  • @strangeqargo Qt 5.7 - Nik
  • 2
    I will then issue the answer, for there are lovers to make answers from other people's comments :-) - strangeqargo

1 answer 1

the reason is in the unfixed bug , I hope the author will bring the solution after the investigation

  • one
    Yes, as I write workaround, I will definitely give a solution. - Nik
  • Tell me, can this ASSERT failure be intercepted and processed? Or is it too fatal error? - Nik
  • almost impossible. can only not reach him - strangeqargo
  • I wanted to override the removeTab(); method removeTab(); - it crashes because of it, but the problem is that it uses many private fields and QTabBar methods. Then I came across D-Pointer , I thought about doing through them, but at the compilation stage an error occurs: невозможно обратится к private член QTabBar::d_func() . I decided to define my d_func() method, the same as in the original, but I did not find the source code. - Nik
  • "However, this patch makes it a QDockWidget," as I understand it, the patch is there. MagicTabWidget from whom is inherited? maybe they managed not to fix all the widgets? - strangeqargo