Providing a copy-paste utility between two Qt applications using clipboard

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): All (S60)
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Keywords: QClipboard
Created: User:Kbwiki (14 Dec 2009)
Last edited: hamishwillee (11 Oct 2012)


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:


 #include <QClipboard>

QClipBoardCopyEx implementation

 class QClipBoardCopyEx : public QWidget
QClipboard* m_clipBoard;

QClipBoardCopyEx implementation

 QClipBoardCopyEx::QClipBoardCopyEx( QWidget *parent )
: QWidget( parent )
// Retrieve pointer to the global clipboard
m_clipBoard = QApplication::clipboard();
QString copyTxt( "From another app!" );
// Copy text to clipboard
m_clipBoard->setText( copyTxt );

QClipBoardPasteEx implementation

 class QClipBoardPasteEx : public QWidget
QLabel* m_label;
QClipboard* m_clipBoard;

Pasting from the global clipboard

 QClipBoardPasteEx::QClipBoardPasteEx(QWidget *parent)
: QWidget(parent)
// 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.

This page was last modified on 11 October 2012, at 01:18.
48 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.