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

[Reg. 5.15-6.x] Returning empty QVariant from list model causes segfault

    XMLWordPrintable

Details

    • Linux/X11
    • dc77f7c71c (qt/qtdeclarative/dev) dc77f7c71c (qt/tqtc-qtdeclarative/dev)

    Description

      The sample code has a custom implemented QAbstratListModel that returns an empty/invalid QVariant as data. When using this model in a (qml) Repeater where the delegate item has it declared as a required property, it causes a segfault.

      QVariant MyModel::data(const QModelIndex&, int) const {
          return QVariant();
      }
      
          Repeater {
              model: MyModel
              delegate: Text {
                  id: delegate
                  text: delegate.name
      
                  required property string name
              }
          }
      
      1  QV4::Function::sourceLocation                    qv4function.cpp           222  0x7ffff74c5327 
      2  QQmlJavaScriptExpression::sourceLocation         qtaggedpointer.h          135  0x7ffff760c01d 
      3  QQmlBinding::sourceLocation                      qqmlbinding.cpp           113  0x7ffff75a9ee5 
      4  QQmlNonbindingBinding::doUpdate                  qqmlbinding.cpp           291  0x7ffff75ad629 
      5  QQmlBinding::update                              qqmlbinding.cpp           199  0x7ffff75a9869 
      6  QQDMIncubationTask::initializeRequiredProperties qqmldelegatemodel.cpp     1037 0x7ffff78e52c3 
      7  QQmlDelegateModelPrivate::setInitialState        qqmldelegatemodel.cpp     1213 0x7ffff78e55e2 
      8  QQmlIncubatorPrivate::incubate                   qqmlincubator.cpp         334  0x7ffff760914b 
      9  QQmlEnginePrivate::incubate                      qqmlincubator.cpp         90   0x7ffff7609414 
      10 QQmlDelegateModelPrivate::object                 qqmldelegatemodel.cpp     1309 0x7ffff78e6caf 
      11 QQuickRepeaterPrivate::requestItems              qquickrepeater.cpp        403  0x7ffff7df5a8f 
      12 QQuickRepeater::componentComplete                qquickrepeater.cpp        347  0x7ffff7df8b73 
      13 QQmlObjectCreator::finalize                      qqmlobjectcreator.cpp     1452 0x7ffff763523e 
      14 QQmlComponentPrivate::complete                   unique_ptr.h              173  0x7ffff75c22a9 
      15 QQmlComponentPrivate::complete                   qqmlcomponent.cpp         1049 0x7ffff75c22a9 
      16 QQmlComponentPrivate::completeCreate             qqmlcomponent.cpp         1147 0x7ffff75c5547 
      17 QQmlComponent::completeCreate                    qqmlcomponent.cpp         1134 0x7ffff75c5693 
      18 QQmlComponent::create                            qqmlcomponent.cpp         866  0x7ffff75c5693 
      19 QQmlApplicationEnginePrivate::finishLoad         qqmlapplicationengine.cpp 158  0x7ffff75a5673 
      20 QQmlApplicationEngine::load                      qqmlapplicationengine.cpp 323  0x7ffff75a5c1c 
      21 main                                             main.cpp                  16   0x404ad6       
      

      We are having code running with Qt 5.15.9 that does not produce the segfault, so this was probably introduced in some 6.x version.

      When implementing a Q_INVOKABLE that returns an empty QVariant, there is a message like this:

      qrc:/riq/main.qml:12:9: Unable to assign [undefined] to QString
      

      I understand that it is not a good idea to use invalid QVariants, but imho it should not result in a segfault. A warning or even exception in the way of the Q_INVOKABLE case would be ok, but right now there is just a stack trace which does not really point to the problem.

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            moerkb Markus Bader
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes