O'Reilly logo

Programming with Qt, 2nd Edition by Matthias Kalle Dalheimer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Interapplication Communication

In this chapter, we will see how two applications can exchange data with each other—except for writing data to a file and then reading it back, of course. This communication can be done between two Qt applications and between Qt applications and other applications that support the same protocols.

There are two techniques for the user-invoked transfer of data from one running application to another: using the clipboard and using drag-and-drop. We will examine each in turn. Of course, these techniques also work within one application, even though they might be less useful then.

Using the Clipboard

The clipboard is an area provided by the operating system or the window system in which data can be deposited. Other applications can then pick up this data. The type of data that can be put in the clipboard depends on the operating or window system, but the less common the datatype, the less likely it is that other applications can use it.

All clipboard operations are done via the class QClipboard. This class follows the singleton pattern, which means there can never be more than one instance of this class. You cannot create an object of this class yourself because its constructor and destructor are private. Instead, ask your QApplication for the QClipboard object by calling QApplication::clipboard().

Let’s first look at how you get data from the clipboard. To make this process easier to understand, imagine that there is not only one QClipboard ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required