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

Crash using a registered singleton QJSValue in QML

    XMLWordPrintable

Details

    Description

      After registering a singleton QJSValue for use in QML scripts, the application crashes when accessing its values.

      See attached file for a minimal program reproducing the crash (relevant material in main.cpp and main.qml, the rest is the stock qtquick2 application viewer).

      Relevant portions of both files:

      Unable to find source-code formatter for language: main.cpp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      static QJSValue qjsvalue_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
      {
          Q_UNUSED(engine)
      
          QJSValue example = scriptEngine->newObject();
          example.setProperty("Normal", 0);
          example.setProperty("Special", 1);
          example.setProperty("Custom", 2);
          return example;
      }
      
      int main(int argc, char *argv[])
      {
          /*...*/
      
          qmlRegisterSingletonType("Content", 1, 0, "ProgramsId", qjsvalue_provider);
      
          /*...*/
      }
      
      Unable to find source-code formatter for language: main.qml. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import QtQuick 2.0
      import Content 1.0
      
      Rectangle {
          width: 360
          height: 360
      
          property int test: ProgramsId.Normal
      }
      

      Setting a QML breakpoint just before the binding that accesses the QJSValue, trying to print "ProgramsId.Normal" results in "SyntaxError:​ Unexpected token ILLEGAL".

      Attachments

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

        Activity

          People

            aalpert Alan Alpert
            lmancini Lorenzo Mancini
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes