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

WebEngine breaks QClipboard::dataChanged()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 6.2.2, 6.3.0
    • WebEngine
    • None
    • Windows 10
    • Windows
    • 72d76568fe (qt/qtwebengine-chromium/98-based) 876c9d734f (qt/qtwebengine-chromium/94-based) 73d8d18f1f (qt/qtwebengine-chromium/90-based)

    Description

      When WebEngine is used in an app, QClipboard::dataChanged() never seems to fire. Whether copying from a simple widget like QLineEdit, copying text from the webview, or copying text from an external application, the signal never fires.

      This can be reproduced using the markdowneditor example app:

      
      --- C:/Qt/Examples/Qt-6.3.0/webenginewidgets/markdowneditor - Copy/mainwindow.cpp
      +++ C:/Qt/Examples/Qt-6.3.0/webenginewidgets/markdowneditor/mainwindow.cpp
      @@ -58,7 +58,8 @@
       #include <QMessageBox>
       #include <QStatusBar>
       #include <QTextStream>
      -#include <QWebChannel>
      +#include <QWebChannel>
      +#include <QClipboard>
       
       MainWindow::MainWindow(QWidget *parent) :
           QMainWindow(parent),
      @@ -89,11 +90,19 @@
           connect(ui->editor->document(), &QTextDocument::modificationChanged,
                   ui->actionSave, &QAction::setEnabled);
       
      +    qInfo() << "setup clipboard";
      +    QClipboard *clip = QGuiApplication::clipboard();
      +    connect(clip, &QClipboard::dataChanged, this, &MainWindow::clipboardChanged);
      +
           QFile defaultTextFile(":/default.md");
           defaultTextFile.open(QIODevice::ReadOnly);
           ui->editor->setPlainText(defaultTextFile.readAll());
       }
       
      +void MainWindow::clipboardChanged() {
      +    qInfo() << "data changed";
      +}
      +
       MainWindow::~MainWindow()
       {
           delete ui;
      
      

      If the sample approach is used on a different example app that doesn't use WebEngine, the signal fires correctly:

      --- C:/Qt/Examples/Qt-6.3.0/widgets/mainwindows/application - Copy/mainwindow.cpp
      +++ C:/Qt/Examples/Qt-6.3.0/widgets/mainwindows/application/mainwindow.cpp
      @@ -261,10 +261,17 @@
           copyAct->setEnabled(false);
           connect(textEdit, &QPlainTextEdit::copyAvailable, cutAct, &QAction::setEnabled);
           connect(textEdit, &QPlainTextEdit::copyAvailable, copyAct, &QAction::setEnabled);
      -#endif // !QT_NO_CLIPBOARD
      -}
      -//! [24]
      -
      +
      +    qInfo() << "setup clipboard";
      +    QClipboard *clip = QGuiApplication::clipboard();
      +    connect(clip, &QClipboard::dataChanged, this, &MainWindow::clipboardChanged);
      +#endif // !QT_NO_CLIPBOARD
      +}
      +//! [24]
      +
      +void MainWindow::clipboardChanged() {
      +    qInfo() << "data changed";
      +}
       //! [32]
       void MainWindow::createStatusBar()
       //! [32] //! [33]
      
      

      This issue does not exist in Qt 5.15.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-102738
          # Subject Branch Project Status CR V

          Activity

            People

              pvarga Peter Varga
              qtdae2 Damien Elmes
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes