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

Dynamically adding State causes Segfault

    XMLWordPrintable

Details

    • Linux/Wayland
    • f905876d6 (dev), 0ae1c61f6 (6.6), 7eb239d43 (6.5)

    Description

      import QtQuick
      import QtQuick.Window
      
      Window {
          id: win
          width: 600
          height: 600
          visible: true
          title: 'sandbox'
      
          Rectangle {
              id: rectItem
              anchors.fill: parent
              color: 'lime'
      
              Component.onCompleted: () => rectItem.states.unshift(myState)
      
              State {
                  id: myState
                  when: win.width > 800
                  PropertyChanges {
                      rectItem.color: 'blue'
                  }
              }
          }
      }
      

      This simple example tries to add a State to an Item's states property dynamically. When running the example, the unshift causes a segfault with this stack trace:

      1  QQuickStateGroupPrivate::replace_states                                                                                                                               qquickstategroup.cpp            179  0x7ffff7b9c8ff 
      2  QV4::PropertyListPrototype::method_unshift                                                                                                                            qqmllistwrapper.cpp             416  0x7ffff753e183 
      3  QV4::FunctionObject::call                                                                                                                                             qv4functionobject_p.h           169  0x7ffff7485789 
      4  QV4::Moth::VME::interpret                                                                                                                                             qv4vme_moth.cpp                 859  0x7ffff7485789 
      5  QV4::Moth::VME::exec                                                                                                                                                  qv4vme_moth.cpp                 541  0x7ffff7489663 
      6  QV4::doCall                                                                                                                                                           qv4function.cpp                 54   0x7ffff73ddbea 
      7  QV4::Function::call                                                                                                                                                   qv4function.cpp                 79   0x7ffff73ddf99 
      8  operator()                                                                                                                                                            qv4function.cpp                 30   0x7ffff73de127 
      9  QV4::convertAndCall<QV4::Function::call(QObject *, void * *, const QMetaType *, int, QV4::ExecutionContext *)::<lambda(const QV4::Value *, const QV4::Value *, int)>> qv4jscall_p.h                   197  0x7ffff73de127 
      10 QV4::Function::call                                                                                                                                                   qv4function.cpp                 27   0x7ffff73de127 
      11 QQmlJavaScriptExpression::evaluate                                                                                                                                    qqmljavascriptexpression_p.h    246  0x7ffff753a0b8 
      12 QQmlBoundSignalExpression::evaluate                                                                                                                                   qqmlboundsignal.cpp             195  0x7ffff74d7e8b 
      13 QQmlBoundSignal_callback                                                                                                                                              qqmlrefcount_p.h                62   0x7ffff74d8780 
      14 QQmlNotifier::emitNotify                                                                                                                                              qqmlnotifier.cpp                70   0x7ffff75626c5 
      15 doActivate<false>                                                                                                                                                     qobject.cpp                     3884 0x7ffff5d9b15e 
      16 QMetaObject::activate                                                                                                                                                 qobject.cpp                     4052 0x7ffff5d93920 
      17 QQmlComponentAttached::completed                                                                                                                                      moc_qqmlcomponentattached_p.cpp 205  0x7ffff74e4dc0 
      18 QQmlObjectCreator::finalize                                                                                                                                           qqmlobjectcreator.cpp           1497 0x7ffff756511b 
      19 QQmlComponentPrivate::complete                                                                                                                                        qbipointer_p.h                  131  0x7ffff74e62d3 
      20 QQmlComponentPrivate::completeCreate                                                                                                                                  qqmlcomponent.cpp               1206 0x7ffff74ebeaf 
      21 QQmlComponent::completeCreate                                                                                                                                         qqmlcomponent.cpp               1184 0x7ffff74ec610 
      22 QQmlComponentPrivate::createWithProperties                                                                                                                            qqmlcomponent.cpp               922  0x7ffff74ec610 
      23 QQmlComponent::create                                                                                                                                                 qqmlcomponent.cpp               873  0x7ffff74ecb74 
      24 QQmlApplicationEnginePrivate::finishLoad                                                                                                                              qqmlapplicationengine.cpp       135  0x7ffff74cac93 
      25 QQmlApplicationEnginePrivate::ensureLoadingFinishes                                                                                                                   qqmlapplicationengine.cpp       162  0x7ffff74cae64 
      26 QQmlApplicationEnginePrivate::startLoad                                                                                                                               qqmlapplicationengine.cpp       109  0x7ffff74cafa7 
      27 QQmlApplicationEngine::load                                                                                                                                           qqmlapplicationengine.cpp       324  0x7ffff74cb24c 
      28 main                                                                                                                                                                  main.cpp                        14   0x402686       
      

      Side note: When using push() instead of unshift(), the state is successfully appended to the states list, but the state is not set when the State's condition applies.

      This is a minimized example. The original use case is that a component A has some states defined and a component B inherits from A, but wants to add own states. Due to the restriction that the "first state wins", it is currently impossible to add a state with "higher priority".

      Attachments

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

        Activity

          People

            vhilshei Volker Hilsheimer
            moerkb Markus Bader
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes