PDA

View Full Version : QTableView->selectionModel()->selection().indexes() crash



musrha85
31st July 2013, 09:27
Hi,

I have a problem and I don´t know the reason. I have a QTableView(ui.tvLotes) with a personal model (that inherit from QAbstractTableModel) and an actionMenu with this triggered event:

void mainScreen:: on_actionEliminar_triggered()
{
QItemSelectionModel *select = ui.tvLotes->selectionModel();
if(select!=NULL)
{
if(select->hasSelection()) //check if has selection
{
QModelIndexList rows=select->selectedRows(); }
}
}

When I use QModelIndexList rows=select->selectedRows(); my program crash with "msvcr100d.dll!_free_base(void * pBlock) LÃ*nea 50 + 0x13Bytes C". I use Visual Studio 2010 in mode debug

I have tried others options like:
connect(ui.tvLotes->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelect ion)),this, SLOT(itemSelectionChanged(QItemSelection,QItemSele ction)));

void mainScreen::itemSelectionChanged(QItemSelection col,QItemSelection row)
{
QModelIndexList indexes=col.indexes();
}

And I have the same crash


For example for this code I havent any problem:
connect(ui.tvLotes->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));

void VentanaPrincipal::currentChanged(QModelIndex old,QModelIndex nuevo)
{
QMessageBox::information (this, "Msg", "OLD -> Row.."+QString::number(old.row())+",col:"+QString::number(old.column())+" NEW -> Row.."+QString::number(nuevo.row())+",col:"+QString::number(nuevo.column()), QMessageBox::Close);
}

ChrisW67
31st July 2013, 09:51
Run your debug version in your debugger. When it crashes read down the stack back trace until the first line of your code. Once you identify exactly which line causes the crash you can inspect the variable values in force at the time. You are most likely looking for a null, uninitialised, or invalid pointer.

musrha85
31st July 2013, 10:46
Thanks for your reply!

I have made the debug and this effect appears when It is call to the destructor of ~QList(), this It is called for this var "QModelIndexList cols=select->selectedColumns();"

template <typename T>
Q_OUTOFLINE_TEMPLATE QList<T>::~QList()
{
if (!d->ref.deref())
dealloc(d);
}


And the final line that makes crash it is in free.c
/***
*free.c - free an entry in the heap
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Defines the following functions:
* free() - free a memory block in the heap
*
************************************************** *****************************/

#include <cruntime.h>
#include <malloc.h>
#include <winheap.h>
#include <windows.h>
#include <internal.h>
#include <mtdll.h>
#include <dbgint.h>
#include <rtcsup.h>

/***
*void free(pblock) - free a block in the heap
*
*Purpose:
* Free a memory block in the heap.
*
* Special ANSI Requirements:
*
* (1) free(NULL) is benign.
*
*Entry:
* void *pblock - pointer to a memory block in the heap
*
*Return:
* <void>
*
************************************************** *****************************/

void __cdecl _free_base (void * pBlock)
{

int retval = 0;


if (pBlock == NULL)
return;

RTCCALLBACK(_RTC_Free_hook, (pBlock, 0));

retval = HeapFree(_crtheap, 0, pBlock);
if (retval == 0)
{
errno = _get_errno_from_oserr(GetLastError());
}
}


could be my Model? I also have a ItemDelegate for one column of my table. I don´t know what might be the problem :(

And I get this message from Visual Studio:
9383