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. QAbstractItemModel::beginInsertRows() crashes with last == -1 only on Windows
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel::beginInsertRows() crashes with last == -1 only on Windows

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.4k 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.
  • H Offline
    H Offline
    halfgaar
    wrote on last edited by
    #1

    Hello,

    I had a bug in my code that I only found out when I built my project for Windows. In:

    @beginInsertRows(index(0,0), 0, devices.count()-1);@

    When devices was empty, the 'last' argument of QAbstractItemModel::beginInsertRows() would be -1. On Windows, this gives a crash with:

    @ASSERT: "last >= first" in file itemmodels\qabstractitemmodel.cpp, line 2542
    Invalid parameter passed to C runtime function.
    Invalid parameter passed to C runtime function.@

    I can understand that the 'invalid parameter passed' error only shows up on Windows, because it may be the Windows API saying it, but why doesn't that ASSERT fail on Linux?

    Qt 5.1.1.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hpollak
      wrote on last edited by
      #2

      could it be, that devices.count() = 0 on Windows?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        halfgaar
        wrote on last edited by
        #3

        Both on Linux and Windows it's 0. The point is, that on Linux there is no ASSERT crash.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hpollak
          wrote on last edited by
          #4

          I think a good method is not to ask why the fault behavior is different on 2 systems, i prefere to ask myself in such sitations, why haven't i seen, that I have forgotten to catch a fault-situation.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            halfgaar
            wrote on last edited by
            #5

            If I look at the "source":https://qt.gitorious.org/qt/qt/source/acc9bc4d9dd3b7a1fef10fe88bfa753e515cdd3e:src/corelib/kernel/qabstractitemmodel.cpp#L2137 of beginInsertRows:

            @void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last)
            {
            Q_ASSERT(first >= 0);
            Q_ASSERT(last >= first);
            Q_D(QAbstractItemModel);
            d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
            emit rowsAboutToBeInserted(parent, first, last);
            d->rowsAboutToBeInserted(parent, first, last);
            }@

            And of Q_ASSERT:

            @#if !defined(Q_ASSERT)

            if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)

            define Q_ASSERT(cond) qt_noop()

            else

            define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,FILE,LINE) : qt_noop())

            endif

            #endif@

            I really don't get it. Both were debug builds. The assert should have failed on Linux too.

            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