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. Why does Qt ColumnView widget crash in this situation?

Why does Qt ColumnView widget crash in this situation?

Scheduled Pinned Locked Moved General and Desktop
qcolumnviewwidgetcrashgui
3 Posts 2 Posters 1.5k Views
  • 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.
  • J Offline
    J Offline
    JKH_
    wrote on 18 Jul 2015, 06:20 last edited by
    #1

    I'm testing an application in Qt that uses a QColumnView widget. The widget has two columns and when an item in the first column (parent) is clicked, it's items (children) are shown in the second column.

    The problem I'm having is this:

    If any parent has more children than there are parents, the application crashes if any of the "excess" children are selected.

    In other words, if there are five parents and each parent has five (or less) children, everything is fine. However, if any parent has six or more children, the application crashes if any child with index greater than the the first five is selected.

    I'm quite sure this is not an error in the code but maybe a bug in Qt itself.

    I hope the above is clear.

    Thanks.

    1 Reply Last reply
    0
    • C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 18 Jul 2015, 06:55 last edited by
      #2

      Hi, welcome to devnet.

      I just tested it (Qt5.5 MSVC2013) and this case works fine. I'm betting it's a bug in your model.

      J 1 Reply Last reply 19 Jul 2015, 14:03
      0
      • C Chris Kawa
        18 Jul 2015, 06:55

        Hi, welcome to devnet.

        I just tested it (Qt5.5 MSVC2013) and this case works fine. I'm betting it's a bug in your model.

        J Offline
        J Offline
        JKH_
        wrote on 19 Jul 2015, 14:03 last edited by
        #3

        @Chris-Kawa Hi, Thank you for the prompt reply. The bug was in my model as you said, but I think I've found the problem.

        It turns out I needed the following:

        if(!hasIndex(row, column, parent))
            return QModelIndex();
        

        In my "QAbstractItemModel::index()" function. I didn't think the view widget would call "index()" with out of bound row/column combinations since it can use "QAbstractItemModel::rowCount()" and QAbstractItemModel::columnCount()" to get the structure of the model.

        Thanks again for your help.

        1 Reply Last reply
        0

        1/3

        18 Jul 2015, 06:20

        • Login

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