Qt logo

QClipboard Class Reference


The QClipboard class provides access to the window systems clipboard. More...

#include <qclipboard.h>

Inherits QObject.

List of all member functions.

Public Members

Signals

Protected Members


Detailed Description

The QClipboard class provides access to the window systems clipboard.

The clipboard offers a simple mechanism to copy and paste data between applications.

QClipboard supports the same data types that drag and drop supports, and uses much of the same mechanisms.

Only a single QClipboard object may exist in an application. This is because QClipboard is a shared window system resource. Call QApplication::clipboard() to access the clipboard.

Example:

    QClipboard *cb = QApplication::clipboard();
    QString text;

    // Copy text from the clipboard (paste)
    text = cb->text();
    if ( text )
        qDebug( "The clipboard contains: %s", text );

    // Copy text into the clipboard
    cb->setText( "This text can be pasted by other programs" );

QClipboard features some convenience functions to access common data types. The methods setText() and text() allow to exchange unicode text easily over the clipboard, while setPixmap(), setImage() and pixmap(), image() allow to exchange QPixmap and QImage between applications.

The most flexible methods are data() and setData(). They allow to put a QMimeSource() on the clipboard or retrieve it from the clipboard. This does not only allow you to put all kind of data type on the clipboard. In addition it allows you to exchange some information using different data types. For example you want to put a sound on the clipboard. Since you can not know exactly what kind of formats the other application understands you can feature multiple formats at once. This functionality is provided by QMimeSource. The application which retrieves the data from the clipboard receives a QMimeSource, too, and can select one of the offered data types.

You can clear the clipboard by calling the method clear().


Member Function Documentation

void QClipboard::clear ()

Clears the clipboard contents.

void QClipboard::connectNotify ( const char * ) [virtual protected]

For internal use only.

Reimplemented from QObject.

QMimeSourceQClipboard::data () const

Returns a reference to a QMimeSource representation of the current clipboard data.

void QClipboard::dataChanged () [signal]

This signal is emitted when the clipboard data is changed.

bool QClipboard::event ( QEvent * e ) [virtual protected]

Handles clipboard events (very platform-specific).

Reimplemented from QObject.

QImage QClipboard::image () const

Returns the clipboard image, or a null image if the clipboard does not contain an image. In addition a null image may be returned if Qt does not understand the provided image format.

See also: setImage(), pixmap() and data().

QPixmap QClipboard::pixmap () const

Returns the clipboard pixmap, or null if the clipboard does not contain any pixmap. Note that this usually looses more information than image().

See also: setPixmap(), image() and data().

void QClipboard::setData ( QMimeSource * src )

Sets the clipboard data. Ownership of the data is transferred to the clipboard - the only way to remove this data is to set something else, or to call clear(). The QDragObject subclasses are reasonable things to put on the clipboard (but do not try to drag the same object). Do not put QDragMoveEvent or QDropEvent subclasses on the clipboard, as they do not belong to the event handler which receives them.

The setText() and setPixmap() functions are shorthand ways of setting the data.

void QClipboard::setImage ( const QImage & image )

Copies image into the clipboard.

This is just a shorthand for:

    setData(new QImageDrag(image))

See also: image(), setPixmap() and setData().

void QClipboard::setPixmap ( const QPixmap & pixmap )

Copies pixmap into the clipboard. Note that this usually looses more information than setImage(), as the data may be converted to an image for transfer.

See also: pixmap(), setImage() and setData().

void QClipboard::setText ( const QString & text )

Copies text into the clipboard.

See also: text() and setData().

QString QClipboard::text () const

Returns the clipboard text, or a null string if the clipboard does not contain any text.

See also: setText() and data().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-2000 Troll Tech, all rights reserved.


Copyright İ 2000 Troll TechTrademarks
Qt version 2.1.0 (pre-release)