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

Cannot set properties on QJSEngine's global object in initializeEngine()

XMLWordPrintable

      void IopluginPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
      {
          QObject *fileObject = new QObject();
      
          QJSValue fileValue = engine->newQObject(fileObject);
          engine->globalObject().setProperty("File", fileValue);
      
          qDebug() << "File value in the global object is:" << engine->globalObject().property("File").toString();
      
          QJSValue str = engine->globalObject().property("String");
          str.setProperty("File", fileValue);
      
          qDebug() << "File value in String object is:" << str.property("File").toString();
      }
      

      The below example prints out:

      File value in the global object is: "" 
      File value in String object is: "QObject(0x102501c60)" 
      

      It seems that it is not possible to write properties to the global object. Is the example code wrong or is this a bug?

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

            aakenned Aaron Kennedy
            sletta Gunnar Sletta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes