Results 1 to 3 of 3

Thread: QTableView->selectionModel()->selection().indexes() crash

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question QTableView->selectionModel()->selection().indexes() crash

    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:"+QStrin g::number(nuevo.column()), QMessageBox::Close);
    }

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTableView->selectionModel()->selection().indexes() crash

    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.

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableView->selectionModel()->selection().indexes() crash

    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:
    assertion.png

Similar Threads

  1. Replies: 21
    Last Post: 13th August 2013, 13:38
  2. QTableView and selectionModel problem
    By unix7777 in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2012, 06:00
  3. QTableView Hidden Sections and Indexes
    By mechsin in forum Newbie
    Replies: 1
    Last Post: 15th July 2012, 18:49
  4. Replies: 2
    Last Post: 26th November 2009, 05:45
  5. SelectionModel
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2007, 14:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.