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

Webkit bridge doesn't work with QPixmap

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.3.2
    • 5.3.1
    • WebKit
    • None
    • KUbuntu 13.04
    • eb611b3f830cb4af80baabadc1f4e71f284ab786

    Description

      C++ code:

      class Global : public QObject
      {
          Q_OBJECT
      
      public slots:
          QPixmap pixmap() const
          {
              QPixmap px(100, 100);
              px.fill(Qt::red);
              return px;
          }
      };
      
      class WebView : public QWebView
      {
          Q_OBJECT
      
      public:
          WebView()
          {
               QObject::connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject()));
          }
      
      public slots:
          void addJSObject()
          {
              page()->mainFrame()->addToJavaScriptWindowObject("global", &m_global);
          }
      
      private:
          Global m_global;
      };
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          WebView *view = new WebView;
      
          view->load(QUrl::fromLocalFile(QApplication::applicationDirPath() + QDir::separator() + "screenshot.html"));
      
          view->show();
      
          return app.exec();
      }

      HTML page:

      <!doctype html>
      <html>
      <head>
      <script>
      
      function go()
      {
              try {
                      var s = global.pixmap();
                      alert("Size: " + s.width + "x" + s.height + "\nType: " + s);
      
                      // CRASH
                      //for(var i in s)
                      //alert(i);
      
                      alert(s.toDataURL());
              } catch(ex) {
                      alert("Exception: " + ex);
              }
      }
      
      </script>
      </head>
      
      <body>
      <button onClick="go()">Go</button>
      </body>
      </html>

      Compile and run. Press "Go" button. Two messages will appear:

      Size: 100x100
      Type: [Qt Native Pixmap 100,100]

      Exception: TypeError: undefined is not a function (evaluating 's.toDataURL()')

      Attachments

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

        Activity

          People

            allan.jensen Allan Sandfeld Jensen
            dmitry64 Dmitry
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes