Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selectionChanged SelectedIndex的Qt插槽调试\u组装\u失败_Qt_Selectionchanged_Selectionmodel - Fatal编程技术网

selectionChanged SelectedIndex的Qt插槽调试\u组装\u失败

selectionChanged SelectedIndex的Qt插槽调试\u组装\u失败,qt,selectionchanged,selectionmodel,Qt,Selectionchanged,Selectionmodel,我的Qt 4.8插槽有问题,它是通过这种方式连接的: connect(ui->objectTree->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(syncGuiWithTreeSelection(const QItemSelection&, const QItemSelection&))); 插

我的Qt 4.8插槽有问题,它是通过这种方式连接的:

connect(ui->objectTree->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(syncGuiWithTreeSelection(const QItemSelection&, const QItemSelection&)));
插槽具有以下签名:

void MyClass::syncGuiWithTreeSelection(const QItemSelection &itemSelected, const QItemSelection &itemDeselected)
在上面的插槽中,我希望访问选定的索引,如下所示:

const QModelIndexList &indexes = itemSelected.indexes();
msvcr90d.dll!operator delete(void * pUserData=0x03673968)  Line 52 + 0x51 bytes C++
MyClass.exe!QModelIndex::`scalar deleting destructor'()  + 0x32 bytes   C++
MyClass.exe!QList<QModelIndex>::node_destruct(QList<QModelIndex>::Node * from=0x0371c4c4, QList<QModelIndex>::Node * to=0x0371c4c8)  Line 431 + 0x2f bytes  C++
MyClass.exe!QList<QModelIndex>::free(QListData::Data * data=0x0371c4b0)  Line 759   C++
MyClass.exe!QList<QModelIndex>::~QList<QModelIndex>()  Line 733 C++
MyClass.exe!MyClass::syncGuiWithTreeSelection(const QItemSelection & itemSelected={...}, const QItemSelection & itemDeselected={...})  Line 853 + 0xc bytes C++
MyClass.exe!MyClass::qt_static_metacall(QObject * _o=0x001ef69c, QMetaObject::Call _c=InvokeMetaMethod, int _id=49, void * * _a=0x001eca04)  Line 247 + 0x20 by
它工作得很好,但是在插槽的末尾,当QModelIndexList的Destructor被调用时,就会出现调试断言失败。调用堆栈如下所示:

const QModelIndexList &indexes = itemSelected.indexes();
msvcr90d.dll!operator delete(void * pUserData=0x03673968)  Line 52 + 0x51 bytes C++
MyClass.exe!QModelIndex::`scalar deleting destructor'()  + 0x32 bytes   C++
MyClass.exe!QList<QModelIndex>::node_destruct(QList<QModelIndex>::Node * from=0x0371c4c4, QList<QModelIndex>::Node * to=0x0371c4c8)  Line 431 + 0x2f bytes  C++
MyClass.exe!QList<QModelIndex>::free(QListData::Data * data=0x0371c4b0)  Line 759   C++
MyClass.exe!QList<QModelIndex>::~QList<QModelIndex>()  Line 733 C++
MyClass.exe!MyClass::syncGuiWithTreeSelection(const QItemSelection & itemSelected={...}, const QItemSelection & itemDeselected={...})  Line 853 + 0xc bytes C++
MyClass.exe!MyClass::qt_static_metacall(QObject * _o=0x001ef69c, QMetaObject::Call _c=InvokeMetaMethod, int _id=49, void * * _a=0x001eca04)  Line 247 + 0x20 by
msvcr90d.dll!运算符删除(Vult*PUSEDATABAS0x0367968)行52 +0x51字节C++
MyClass.exe!qMultCurrase::“标量删除析构函数”(++0x32字节C++)
MyClass.exe!qList::NoDEYBASECT(QList::No.*from 0x031C4C4,qList::No.*to= 0x031C4C8)431 +0x2f字节C++
MyClass.exe!QList::FLASE(QListData::Data *数据=0x037 1C4B0)759 C++
MyClass.exe!qList::~qList.()733行C++
MyClass.exe!MyClass::SycGuiGueTeeSeRead(const QITEMONCENTITY={…},const qITEMONCECTIONITIDECEDCENCE= {…})行853 +0xC字节C++
MyClass.exe!MyClass::qt_static_metacall(QObject*_o=0x001ef69c,QMetaObject::Call _c=InvokeMetaMethod,int _id=49,void**_a=0x001eca04)第247+0x20行by
要访问所选索引,我可以做些什么


向你问好,莱因哈特

在你的位置上你还做些什么?看起来您删除了一些对象两次。它只包含“itemSelected.indexes();”。当这句话被删除时,一切都很好。如果我试图通过插槽中的“ui->objectTree->selectionModel()->SelectedIndex()”访问SelectedIndex,则会出现相同的错误。如果我把那句话放在连接之后,一切都很好。我的投币口有问题吗?似乎在访问插槽中的SelectedIndex时出现了一般性问题。
QItemSelection::indexes()
返回
QModelIndexList
,因此我认为您需要调用:
QModelIndexList indexes=itemsSelected.indexes()
。只是尝试了一下-不起作用。语句
QItemSelection::index()
足以让代码中断。