QClipboard(3qt)

NAME
QClipboard - Access to the window system clipboard

#include <qclipboard.h>

Inherits QObject.

  Public Members
void clear ()
QMimeSource* data () const
void setData ( QMimeSource * )
QString text () const
QString text ( QCString & subtype ) const
void setText ( const QString & )
QImage image () const
QPixmap pixmap () const
void setImage ( const QImage & )
void setPixmap ( const QPixmap & )

  Signals
void dataChanged ()

  Protected Members
virtual void connectNotify ( const char * ) (internal)

DESCRIPTION
The QClipboard class provides access to the window system clipboard.

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

QClipboard supports the same data types that QDragObject does, and uses similar mechanisms. For advanced clipboard usage, you should read the drag-and-drop documentation.

There is only one QClipboard object in an application, and you can gain access to it using QApplication::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() allows exchanging unicode text easily over the clipboard, while setPixmap() setImage() allows to exchange QPixmap and QImage between applications. setData() is the ultimate in flexibility: It allows you to add any QMimeSource onto the clipboard. (There are corresponding getters for each of these, e.g. text().)

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

MEMBER FUNCTION DOCUMENTATION

void QClipboard::clear ()
Clears the clipboard contents.

QMimeSource* QClipboard::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]
Reimplemented for internal reasons; the API is not affected.

Reimplemented from QObject.

QImage QClipboard::image () const
Returns the clipboard image, or a null image if the clipboard does not contain an image, or if it contains an image in an unsupported image format.

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

QPixmap QClipboard::pixmap () const
Returns the clipboard pixmap, or null if the clipboard does not contain any pixmap. Note that this can lose information - for example, if the image is 24-bit and the display 8-bit the result is converted to 8 bits, and if the image has an alpha channel the result just has a mask.

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

void QClipboard::setData ( QMimeSource * src )
Sets the clipboard data. Ownership of the data is transferred to the clipboard - the only ways 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 call QDragObject::drag() on the same object). Any QDragObject placed in the clipboard should have a parent of 0. 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 simpler wrappers for this.

void QClipboard::setImage ( const QImage & image )
Copies image into the clipboard.

This is 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 is slower than setImage() - it needs to convert the QPixmap to a QImage first.

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 as plain text, or a null string if the clipboard does not contain any text.

See also setText(), data() and QString::operator!().

QString QClipboard::text ( QCString & subtype ) const
Returns the clipboard text in subtype subtype, or a null string if the clipboard does not contain any text. If subtype is null, any subtype is acceptable, and subtype is set to the chosen subtype.

Common values for subtype are "plain" and "html".

See also setText(), data() and QString::operator!().

void QClipboard::connectNotify ( const char * ) [virtual protected]
For internal use only.

Reimplemented from QObject.

SEE ALSO
http://doc.trolltech.com/qclipboard.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qclipboard.3qt) and the Qt version (2.3.0).