[SOLVED] QClipboard::mimeData() returns null

  • Hello,

    I am trying to use QClipboard on N9 and Meego and it looks like does not work, the same code works when running in Desktop.

    I have tried the following simple code both on N9 simulator and nemo virtual machine:

    widget class header
    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>
    class QPushButton;
    class QClipboard;

    class Widget : public QWidget
    explicit Widget(QWidget *parent = 0);
    public slots:
    void putUrls();
    void putText();
    void showData();
    void clipboardChanged();
    QPushButton *getBtn;
    QPushButton *putUrlBtn;
    QPushButton *putTextBtn;
    QClipboard *clip;
    #endif // WIDGET_H

    widget class
    #include "widget.h"
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QClipboard>
    #include <QDebug>
    #include <QMimeData>
    #include <QStringList>
    #include <QUrl>
    #include <QTemporaryFile>
    #include <QApplication>
    #include <QShowEvent>
    #include <QWidget>

    Widget::Widget(QWidget *parent) :
    , clip(0)
    QVBoxLayout *lay = new QVBoxLayout(this);
    getBtn = new QPushButton("show clipboard", this);
    putUrlBtn = new QPushButton("put url", this);
    putTextBtn = new QPushButton("put text", this);
    connect(getBtn, SIGNAL(clicked()), this , SLOT(showData()));
    connect(putUrlBtn, SIGNAL(clicked()), this, SLOT(putUrls()));
    connect(putTextBtn,SIGNAL(clicked()), this, SLOT(putText()));

    void Widget::putText()
    QClipboard * clipboard = QApplication::clipboard();
    if ( clipboard ) {
    clipboard->setText( QLatin1String("has text") );
    }else {
    qDebug() << Q_FUNC_INFO << "no clipboard";

    void Widget::putUrls()
    QTemporaryFile temp;
    QByteArray d ("11212121212\n");
    temp.write(d) ;
    QClipboard * clipboard = QApplication::clipboard();
    if ( clipboard )
    QMimeData *mime= new QMimeData();
    QUrl url(QUrl::fromLocalFile(temp.fileName()));
    qDebug() << "valid" << url.isValid() << url.toString();
    QList<QUrl> files;
    clipboard->setMimeData(mime, QClipboard::Clipboard);
    qDebug() << "\n\n--------- ";

    void Widget::showData()
    QClipboard *clipboard = QApplication::clipboard();
    if ( clipboard )
    if (clip == 0)
    clip = clipboard;
    connect(clip, SIGNAL(dataChanged()), this, SLOT(clipboardChanged()));
    const QMimeData * mime = clipboard->mimeData(QClipboard::Clipboard);
    if (mime == 0)
    qDebug("QClipboard::mimeData() returns null");

        QStringList formats = mime->formats();
        for(int counter=0; counter &lt; formats.count(); counter++)
            QByteArray d = mime-&gt;data(formats.at(counter));
            if (!d.isEmpty())
                qDebug() << "format" <&lt; formats.at(counter) &lt;&lt; "data" << d << endl;


    void Widget::clipboardChanged()
    qDebug() << Q_FUNC_INFO << "clipboard changed";


    #include <QApplication>
    #include "widget.h"

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    Widget w;
    return a.exec();

  • Since QClipboard is a wrapper to a global clipboard object provided by the underlying operating system (some people say just the underlying window system) of a platform(device), could it be that those platforms are so primitive they do not support such a clipboard?

    Or is the simulator (of the platform) so primitive that it omits the clipboard of the platform?

    How hard would it be to test on the real platform?

  • Thanks,

    Nemo emulator is a real Linux and uses X window, N9 emulator I do not know.

    I will try to test that in a N9 device.

  • Hi Bootchk you' re right,

    In N9 device it works as expected,

    I thought it would work in emulators.

    Thank you

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.