Anomalous WebView editing behavior

  • In building an application using QWebView with content editable I've run some weird behavior. After some work I've pared down my code to illustrate some of this behavior. The test HTML I'm using is in a file called undotest.html and is as follows:

    <!DOCTYPE html>
    <title>undo_redo test</title>
    <!-- undo_redo test -->
    <p>start undo_redo test</p>
    <iframe width="420" height="315" src="" frameborder="0" allowfullscreen></iframe>
    <p>end undo_redo test</p>

    The test program that displays the HTML is simply a webView with three push buttons. An undo button, a redo button, and a cut button. The mainwindow.cpp where all the action takes place is:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QUrl>
    #include <QDebug>
    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    QUrl url("path to undotest.html");
    delete ui;
    void MainWindow::on_undoButton_clicked()
    }// end on_undoButton_clicked
    void MainWindow::on_redoButton_clicked()
    }// end on_redoButton_clicked
    void MainWindow::on_cutButton_clicked()
    }// end on_cutButton_clicked@

    As simple as this code is it produces the following anomalous results:

    • If you select the iframe (i.e., the youtube video) and press cut the video is successfully cut. You can then press undo to restore the video but after that the redo button no longer works (but you can still press cut and it will work).
    • If you first select some text from start “undo_redo test” and cut it then cut the video you should be able to press undo twice to restore the original content but it doesn't happen. Pressing the undo button once restores the video but pressing it again has no effect. After some further investigation I found that the first undo causes webview to emit a loadStarted() signal which appears to clear the undo stack. Note: if the order of operations is reversed everything works okay.

    If I use the <object> HTML from YouTube to display the video then the QWebView code works correctly so as a temporary measure I'm using the old YouTube HTML rather than their recommended HTML but eventually one would have to be able to switch to the recommended HTML.

    Does anyone have any suggestions for an actual work around for this problem?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.