Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Clearing a QTreeWidget in CustomContextMenuRequest causes crash

Clearing a QTreeWidget in CustomContextMenuRequest causes crash

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PerryKipKerrie
    wrote on last edited by
    #1

    Hi,

    I'm struggling to get the following work:
    Ive connected a CustomContextMenuRequest to a QWidgetTree and indeed the menu pops open. But, however, when I want to clear this QWidgetTree in this request I get a null pointer exception. When i run this piece of code in another place or slot it works just fine.

    When there are multiple items present in the treewidget, i can delete them one for one, and everything works fine, but when I delete the last one the exception occurs again.

    void N3LAB_Software::contextMenuTree(const QPoint& pos){
    this->objectList->clear(); % The QTreeWidget
    }
    
    

    Does somebody know whats causing this problem or how to fix this?

    Thanks,

    Perry

    Ps:
    Im using Qt 5.6 with visual studio 2015

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Can you post your stack trace at the moment of the crash?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PerryKipKerrie
        wrote on last edited by PerryKipKerrie
        #3

        Sure, here it is

        Qt5Widgetsd.dll!QTreeWidgetItem::text(int column) Line 106	C++
        N3LAB_Software.exe!N3LAB_Software::changedModelSelection(QTreeWidgetItem * currentItem, QTreeWidgetItem * oldItem) Line 276	C++
         	N3LAB_Software.exe!N3LAB_Software::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 108	C++
         	Qt5Cored.dll!QMetaObject::activate(QObject * sender, int signalOffset, int local_signal_index, void * * argv) Line 3742	C++
         	Qt5Cored.dll!QMetaObject::activate(QObject * sender, const QMetaObject * m, int local_signal_index, void * * argv) Line 3603	C++
         	Qt5Widgetsd.dll!QTreeWidget::currentItemChanged(QTreeWidgetItem * _t1, QTreeWidgetItem * _t2) Line 441	C++
         	Qt5Widgetsd.dll!QTreeWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex & current, const QModelIndex & previous) Line 2303	C++
         	Qt5Widgetsd.dll!QTreeWidget::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 212	C++
         	Qt5Cored.dll!QMetaObject::activate(QObject * sender, int signalOffset, int local_signal_index, void * * argv) Line 3742	C++
         	Qt5Cored.dll!QMetaObject::activate(QObject * sender, const QMetaObject * m, int local_signal_index, void * * argv) Line 3603	C++
         	Qt5Cored.dll!QItemSelectionModel::currentChanged(const QModelIndex & _t1, const QModelIndex & _t2) Line 488	C++
         	Qt5Cored.dll!QItemSelectionModel::clearCurrentIndex() Line 1320	C++
         	Qt5Cored.dll!QItemSelectionModel::clear() Line 1308	C++
         	Qt5Widgetsd.dll!QTreeWidget::clear() Line 3258	C++
         	N3LAB_Software.exe!N3LAB_Software::contextMenuTree(const QPoint & pos) Line 175	C++
        
        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Crash seems to be in N3LAB_Software::changedModelSelection(QTreeWidgetItem * currentItem, QTreeWidgetItem * oldItem) Line 276 almost surely you are trying to use an item that was deleted. can you post the code of that method?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • P Offline
            P Offline
            PerryKipKerrie
            wrote on last edited by
            #5

            @VRonin said in Clearing a QTreeWidget in CustomContextMenuRequest causes crash:

            QTreeWidgetItem

            Thank you very much, that I did not see this.

            The changedModelSelection(QTreeWidgetItem* currentItem, QTreeWidgetItem* oldItem) which is called when a selection is changed in the tree wants to do an update, but as there are no objects left the currentItem is null and there for causes an exception when I want to do something with it.

            4 days strugling for this, haha.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved