Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Providing a copy-paste utility between two Qt applications using clipboard
This article describes how to provide a copy-paste operation between two Qt applications.
QClipboard can be used to get access to the system clipboard. Every application has access to the global clipboard object with QApplication::clipboard().
Lets assume there are two Qt applications:
- QClipBoardCopyEx Copies some data to the global clipboard
- QClipBoardPasteEx Retrieves data from the global clipboard
Support for copy-paste operations between these applications can be implemented as follows:
Pasting from the global clipboard
// Retrieve a pointer to the global clipboard
m_clipBoard = QApplication::clipboard();
// Retrieve text from the global clipboard
QString pasteTxt = m_clipBoard->text();
m_label = new QLabel( this );
// Show the text in a label
m_label->setText( pasteTxt );
m_label->setGeometry( QApplication::desktop()->availableGeometry() );
To get notifications of the changes to clipboard contents, connect the QClipboard::dataChanged() signal to an appropriate slot in the application.