- 
    Bug 
- 
    Resolution: Done
- 
    P2: Important 
- 
    None
- 
    6.2.2, 6.3.0
- 
    None
- 
    Windows 10
- 
        
- 
        72d76568fe (qt/qtwebengine-chromium/98-based) 876c9d734f (qt/qtwebengine-chromium/94-based) 73d8d18f1f (qt/qtwebengine-chromium/90-based)
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.
- is duplicated by
- 
                    QTBUG-101918 QClipboard::dataChanged() was not emitted in QtWebEngine context -           
- Closed
 
-         
- relates to
- 
                    QTBUG-82578 When setting data to the clipboard there is no dataChanged() signal emitted from QClipboard class -           
- Closed
 
-         
- 
                    QTBUG-83300 [REG 5.14.0->5.14.1] QWebEngine prevents QClipboard::dataChanged to be triggered -         
- Closed
 
-