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

Webkit bridge doesn't work with QPixmap

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.3.1
    • Fix Version/s: 5.3.2
    • Component/s: WebKit
    • Labels:
      None
    • Environment:
      KUbuntu 13.04
    • Commits:
      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

            • Assignee:
              allan.jensen Allan Sandfeld Jensen
              Reporter:
              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