QClipboard *clipboard = QGuiApplication::clipboard(); QByteArray data = "Clipboard Data"; QMimeData *mimeData = new QMimeData(); mimeData->setData("text/plain", data); // Set clipboard data to text/plain format clipboard->setMimeData(mimeData); // Set MimeData object to clipboard
QClipboard *clipboard = QGuiApplication::clipboard(); QUrl fileUrl("file:///path/to/file"); // Path to file QMimeData *mimeData = new QMimeData(); mimeData->setUrls(QListIn this example, we are setting the clipboard data to a file URL format using QUrl. Package/Library: The package library used in this example is the Qt Library for C++ programming language.() << fileUrl); // Set clipboard data to file URL format clipboard->setMimeData(mimeData); // Set MimeData object to clipboard