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

Invocation of a C++ static method via an inherited QML singleton causes a crash

    XMLWordPrintable

Details

    Description

      After the changes introduced by QTBUG-115115 our project crashes on startup somewhere inside the QML engine. Debug version of the Qt asserts in qv4qobjectwrapper.cpp. Stack trace looks like this:

      __pthread_kill_implementation (@__pthread_kill_implementation:79)
      raise (@raise:12)
      abort (@abort:52)
      qAbort() (/home/kds/dev/qt_build/src/qtbase/src/corelib/global/qglobal.cpp:161)
      ::qt_message_fatal(QtMsgType, const QMessageLogContext &, const QString &) (/home/kds/dev/qt_build/src/qtbase/src/corelib/global/qlogging.cpp:2059)
      QMessageLogger::fatal(char const*, ...) const (/home/kds/dev/qt_build/src/qtbase/src/corelib/global/qlogging.cpp:939)
      qt_assert(char const*, char const*, int) (/home/kds/dev/qt_build/src/qtbase/src/corelib/global/qassert.cpp:68)
      QV4::Heap::QObjectMethod::checkThisObject(QMetaObject const*) const (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4qobjectwrapper.cpp:2472)
      QV4::QObjectMethod::callInternal(QV4::Value const*, QV4::Value const*, int) const (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4qobjectwrapper.cpp:2647)
      QV4::QObjectMethod::virtualCall(QV4::FunctionObject const*, QV4::Value const*, QV4::Value const*, int) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4qobjectwrapper.cpp:2617)
      QV4::FunctionObject::call(QV4::Value const*, QV4::Value const*, int) const (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4functionobject_p.h:169)
      QV4::Moth::VME::interpret(QV4::JSTypesStackFrame*, QV4::ExecutionEngine*, char const*) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4vme_moth.cpp:873)
      QV4::Moth::VME::exec(QV4::JSTypesStackFrame*, QV4::ExecutionEngine*) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4vme_moth.cpp:555)
      QV4::doCall(QV4::Function *, const QV4::Value *, const QV4::Value *, int, QV4::ExecutionContext *) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4function.cpp:54)
      QV4::Function::call(QV4::Value const*, QV4::Value const*, int, QV4::ExecutionContext*) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4function.cpp:79)
      operator() (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4function.cpp:30)
      QV4::convertAndCall<QV4::Function::call(QObject*, void**, const QMetaType*, int, QV4::ExecutionContext*)::<lambda(const QV4::Value*, const QV4::Value*, int)> >(QV4::ExecutionEngine *, QObject *, void **, const QMetaType *, int, (unnamed struct)) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4jscall_p.h:197)
      QV4::Function::call(QObject*, void**, QMetaType const*, int, QV4::ExecutionContext*) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/jsruntime/qv4function.cpp:27)
      QQmlJavaScriptExpression::evaluate(void**, QMetaType const*, int) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmljavascriptexpression.cpp:270)
      QQmlBoundSignalExpression::evaluate(void**) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlboundsignal.cpp:199)
      QQmlBoundSignal_callback(QQmlNotifierEndpoint*, void**) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlboundsignal.cpp:314)
      QQmlNotifier::emitNotify(QQmlNotifierEndpoint*, void**) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlnotifier.cpp:70)
      QQmlData::signalEmitted(QAbstractDeclarativeData*, QObject*, int, void**) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlengine.cpp:360)
      void doActivate<false>(QObject*, int, void**) (/home/kds/dev/qt_build/src/qtbase/src/corelib/kernel/qobject.cpp:3928)
      QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (/home/kds/dev/qt_build/src/qtbase/src/corelib/kernel/qobject.cpp:4096)
      QQmlComponentAttached::completed() (/home/kds/dev/qt_build/build/qtdeclarative/src/qml/Qml_autogen/include/moc_qqmlcomponentattached_p.cpp:205)
      QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlobjectcreator.cpp:1517)
      QQmlComponentPrivate::complete(QQmlEnginePrivate*, QQmlComponentPrivate::ConstructionState*) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlcomponent.cpp:1136)
      QQmlComponentPrivate::completeCreate() (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlcomponent.cpp:1241)
      QQmlComponent::completeCreate() (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlcomponent.cpp:1219)
      QQmlComponentPrivate::createWithProperties(QObject*, QMap<QString, QVariant> const&, QQmlContext*, QQmlComponentPrivate::CreateBehavior) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlcomponent.cpp:957)
      QQmlComponent::create(QQmlContext*) (/home/kds/dev/qt_build/src/qtdeclarative/src/qml/qml/qqmlcomponent.cpp:908)
      runUi(QGuiApplication*) (.../main.cpp:113)
      runApplication(QGuiApplication*) (.../main.cpp:177)
      main (.../main.cpp:365)
      __libc_start_call_main (@__libc_start_call_main:31)
      __libc_start_main@@GLIBC_2.34 (@__libc_start_main@@GLIBC_2.34:46)
      _start (@_start:14) 

      This is what leads to the crash:

      1. Create a C++ class inherited from QObject.
      2. Add a Q_INVOKABLE static method.
      3. Register the class as a creatable component to QML.
      4. Create a QML component inherited from this C++ class and declare it as a singleton in qmldir.
      5. Now in another QML file call the static method from (2) via the QML object declared in (4).
      6. The app will crash or fails the assertion.

      For simplicity I prepared a minimal example. Please see the attachment.

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              kds Denis Klychkov
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes