title: Qt Webkit bridge ActiveQt string
body: <p>See also for part of my issue: <a href="https://stackoverflow.com/questions/7865715/string-passing-from-javascript-to-qt-c-object">String passing from JavaScript to Qt/C++ object</a></p>
  
  <p>I use this custom <code>WebPage</code> on my <code>WebView</code> (using <code>setPage</code>), the strings are passed in wrongly. When I disable calling <code>setPage</code>, the strings passed correctly.</p>
  
  <p>I have a C++ object (that inherits from <code>QWidget</code>) that displays an activeX on a webpage (using <code>ActiveQt</code> and <code>QWebView</code>). The ActiveX object displays just fine. I've registered the custom type and used the Qt MetaType system to instantiate the HTML object.</p>
  
  <p>If I want to update a property of that C++ object (not the ActiveX) and call  from JavaScript, the string gets a wrong translation or so. If I pass in  some string, I only get a string of 1 character on my C++ method. Viewing the memory tells me that the whole string is present (formattted as UTF-32).</p>
  
  <p>If I now don't call the custom <code>WebPage</code> that loads the plugin for me (using <code>setPage</code> on <code>QWebView</code>), I don't get the ActiveX - which is expected - and the strings are passed correctly.</p>
  
  <p>I don't quite understand why this doesn't work. Even with <code>setPage</code> called, I'm talking to the C++ object via JavaScript/QtWebKit bridge, not to the ActiveX component.</p>
  
  <p>I'm on Windows 7, 64 bit, using Qt 4.7.4.</p>
  
  <p>Some code (C++):</p>
  
  <pre><code>class Device : public QWidget
  {
      Q_OBJECT
  
  public:
      explicit Device(QWidget* parent = 0);
      Device(const Device&amp; other);
      Device&amp; operator=(const Device&amp; other);
      ~Device();
  
      QString name() const;
      void setName(QString);
      Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
  signals:
      void nameChanged(QString);    
  private:
      QAxWidget* ax;
  };
  Q_DECLARE_METATYPE(Device);
  
  Device::Device(QWidget* parent/* = 0*/)
      : QWidget(parent)
  {
      ax = new QAxWidget(this);
      ax-&gt;setControl("{...}");
  }
  
  QString Device::name() const
  {
      return _name;
  }
  
  void Device::setName(QString name)
  {
      if (_name != name) {
          _name = name;
          emit nameChanged(name);
      }
  }
  
  // Needed for ActiveQt objects to work
  class MapPage : public QWebPage
  {
      Q_OBJECT
  protected:
      QObject* createPlugin(const QString&amp; classId, const QUrl&amp; url, const QStringList&amp; paramNames, const QStringList&amp; paramValues);
  
  public:
      MapPage(QObject* parent = 0);
  };
  
  // ============================================================================
  // Needed for ActiveQt objects to work
  MapPage::MapPage(QObject* parent/* = 0*/)
      : QWebPage(parent)
  {
      qRegisterMetaType&lt;Device&gt;();
      settings()-&gt;setAttribute(QWebSettings::PluginsEnabled, true);
  }
  
  QObject* MapPage::createPlugin(const QString&amp; classId, const QUrl&amp; url, const QStringList&amp; paramNames, const QStringList&amp; paramValues)
  {
      // Create widget using QUiLoader, which means widgets don't need to be registered with meta object system (only for gui objects!).
      QUiLoader loader;
  
      QObject* result = 0;//loader.createWidget(classId, view());
  
      // If loading failed, use the Qt Metatype system; expect objects derived from QObject
      if (!result) {
          //result = static_cast&lt;QWidget*&gt;(QMetaType::construct(QMetaType::type(classId.toLatin1())));
          int id = QMetaType::type("Device");
          void* classPtr = QMetaType::construct(id);
          result = static_cast&lt;QWidget*&gt;(classPtr);
      }
  
      return result;
  }
  </code></pre>
  
  <p>and then on my window</p>
  
  <pre><code>qRegisterMetaType&lt;Device&gt;();
  mapPage = new MapPage(this);
  ui.webView-&gt;setPage(mapPage);   // Needed for ActiveQt objects to work - makes strings broken
  ...
  ui.webView-&gt;setHtml(src);
  </code></pre>