Results 1 to 4 of 4

Thread: QModelIndex::internalID and QAbstractItemModel::createIndex type mismatch?

  1. #1
    Join Date
    Jun 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QModelIndex::internalID and QAbstractItemModel::createIndex type mismatch?

    QModelIndex::internalID returns qint64 but QAbstractItemModel::createIndex takes quint32 as parameter. I found this to be a little confusing. Is part of internal id reserved by Qt or is this a bug?

  2. #2
    Join Date
    Jun 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QModelIndex::internalID and QAbstractItemModel::createIndex type mismatch?

    It does seem odd. "Is it a bug?" depends on whether it was done that way on purpose. The internal ID is just the void* internal pointer cast to an integer. So I guess internalId returns a 64-bit integer to allow for platforms with 64-bit pointers. Why the createIndex parameter should be 32-bit I don't know... backward compatibility perhaps?

    What I think is a bug is that QModelIndex::internalId does this: return reinterpret_cast<qint64>(p); On a platform with 32-bit pointers this casts a 32-bit value to a 64-bit value, and I don't think the result is properly defined.

    I used the internal ID to store a negative value, and the value I got back from QModelIndex::internalId was compiler-dependant. Visual C++ (Windows) and gcc (Linux) gave me back my original negative value in 64-bit form (I guess they first reinterpreted the 32-bit pointer as an int32 and then promoted it to an int64: 0xFFFFFFFF -> 0xFFFFFFFFFFFFFFFF). Sun Studio (Solaris) took the 32-bit value and left-padded with zeros, giving me back a completely different number (0xFFFFFFFF -> 0x00000000FFFFFFFF).

    You might say I shouldn't have passed a signed value to a function that takes a uint32; but the same problem would affect a 32-bit unsigned value with a high-bit of 1.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QModelIndex::internalID and QAbstractItemModel::createIndex type mismatch?

    I don't think it is a bug, might be some portability workaround. I don't see any problem with this, I have used this earlier.

    You can either store a void* or quint32, just forget about the implementation...If you want to store void * use internalPointer(), else use internalID(), you should not have any problems as long as don't mix the usage.

  4. #4
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QModelIndex::internalID and QAbstractItemModel::createIndex type mismatch?

    Addresses are supposed to be positive numbers. And quint32 and qint64 are promised to be 32 bit and 64 bit respectively on all supported platforms by qt. So you cannot run into trouble because of this. As of use, I have used many many times with no problems.

Similar Threads

  1. Replies: 20
    Last Post: 1st July 2015, 01:19
  2. Hello World tutorial version mismatch?
    By nortonglider in forum Newbie
    Replies: 4
    Last Post: 5th March 2010, 11:12
  3. QSslSocket hostname mismatch
    By eleanor in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2009, 17:48
  4. Class name mismatch for plugin
    By martinb0820 in forum Qt Tools
    Replies: 3
    Last Post: 20th August 2008, 13:47
  5. Replies: 6
    Last Post: 21st September 2007, 13:51

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.