Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebview and Qthread
Forum Updated to NodeBB v4.3 + New Features

QWebview and Qthread

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarahjohn
    wrote on last edited by
    #1

    Hi,
    I am writing a qt browser application which is sending the screen shots of the webpage to an android tab through qt sockets.
    @QString MainWindow::saveResult()

    {
    QString file;

      if(view->page()->mainFrame())
    {
    // save each frame in different image files
      file=saveFrame(view->page()->mainFrame());
    }
     return file;
    

    }

    QString MainWindow::saveFrame(QWebFrame *frame)
    {
    static int frameCounter = 0;

    QString fileName="FRAMECAPTURE.jpg";
    
    if (frameCounter) {
        int index = fileName.lastIndexOf('.');
        fileName = fileName.insert(index, "_frame" + QString::number(frameCounter));
    }
    
    QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied);
    image.fill(Qt::transparent);
    
    QPainter painter(&image);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);
    painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
    frame->render(&painter);
    

    painter.end();
    image.save("./CAPTUREIMAGES/"+fileName,"JPG");
    ++frameCounter;
    foreach(QWebFrame *childFrame, frame->childFrames())
    saveFrame(childFrame);
    return fileName;

    }@

    This is the code I used to save the webpage to a file and in next I am sending the image to a client ie, an application in android Tab.From the android Tab I am getting the coordinates of the images,buttons etc on the webpage and send back to the browser and I make changes to the webpage using the code below.
    @
    void MainWindow::processEvent(QPoint coordinate)
    {

    QPoint pos=coordinate;
    QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    QApplication::sendEvent(view->page(), &event0);
    QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    QApplication::sendEvent(view->page(), &event1);

    QString fileName=saveResult();
    qDebug()<<"FILENAME"<<file;
    emit sendImage(fileName);
    }
    @
    The problem comes when is , after posting the event to the view and calling saveResult(). The image saved is the the previous webpage and not the changed page after sendEvent().How can I save the changed webpage.Please help.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Where and how is the QThread mentioned in the topic title involved?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sarahjohn
        wrote on last edited by
        #3

        actually the event is received over network and a thread started when client connection is established.thread actually recieves the input event and signals the processevent() function in mainwindow.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          I think your problem is that you expect that the widget is completely updated after you have send the mouse events. It is not.

          Mouse events may trigger changes in the web view. In such cases, the web view will call update(). This will schedule an update of the widget. The actual update happens on a next iteration of the event loop. However, at the moment. you've already rendered the view into your file and send that. You've circumvented using the event loop for the mouse events, but you can't do the same for the update cycle I think.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sarahjohn
            wrote on last edited by
            #5

            But the webpage is changing instantly receiving the mouse click events.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              And as I explained, that does not mean that the rest of the whole update process is executed immediately. I only pointed at the paint update being asynchronous, but the web view itself may also do part of its work asynchronous. There simply is no guarantee that the view will be updated immediately after it receives clicks. Only that it will update if needed, but it is not telling you when.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sarahjohn
                wrote on last edited by
                #7

                So how can I make my saveResult() call only after the complete qwebview update. Is there any signals emitted or something like that,so i can call the saveResult() function to capture the changed webpage.?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved