Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-99274

Complete migration from int to qsizetype [item models]




      According to the Qt6 changes docs here: https://doc.qt.io/qt-6/qtcore-changes-qt6.html#qvector-qlist

       Many of the 'int' types have been changed to 'qsizetype'.

      While that is a fine change by itself, dealing with this change in existing code is very painful because not ALL of the Qt APIs have made this change. For example, many widget and model-view classes still use 'int', so passing data between the container classes and these other APIs is not compatible. My suggestion is to unify the API and use qsizetype consistently across the entire Qt class hierarchy.


      For example, the QModelIndex class still uses 'int' for row and column. It should be updated to 'qsizetype'.

      Even more painful is that QAbstractItemModel::rowCount() and QAbstractItemModel::columnCount() return 'int'. They should return 'qsizetype'. For example, in cases where I have a custom model that uses a Qt container class, the container 'size()' method now returns a 'qsizetype', but I have to cast it to an 'int' in my virtual override of rowCount(). Hopefully this gets the point across.

      A widget example is QComboBox::count() and currentIndex() are both 'int', but should now be 'qsizetype'.

      I don't know if anyone else feels the same, but my porting experience dealing with this issue has been very painful, and it is going to take me a long to update our code. One reason it is hard for me specifically is because MSVC 2019 gives a warning in many cases, like "warning C4244: 'argument': conversion from 'qsizetype' to 'int', possible loss of data" and we enforce compiler warnings-to-errors in our build. So I have to fix all of these in order for our code to even compile cleanly.

      Interestingly, QString has mostly updated to 'qsizetype' like the container classes. I guess I don't understand why the datatype change was not propagated globally to all API functions. It is difficult to deal with.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            dfaure_kdab David Faure
            pendletonic Corey Pendleton
            1 Vote for this issue
            4 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes