Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] QClipboard::mimeData() returns null
QtWS25 Last Chance

[SOLVED] QClipboard::mimeData() returns null

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cmazieri
    wrote on last edited by
    #1

    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
    {
    Q_OBJECT
    public:
    explicit Widget(QWidget *parent = 0);
    public slots:
    void putUrls();
    void putText();
    void showData();
    void clipboardChanged();
    private:
    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) :
    QWidget(parent)
    , clip(0)
    {
    QVBoxLayout *lay = new QVBoxLayout(this);
    getBtn = new QPushButton("show clipboard", this);
    lay->addWidget(getBtn);
    putUrlBtn = new QPushButton("put url", this);
    lay->addWidget(putUrlBtn);
    putTextBtn = new QPushButton("put text", this);
    lay->addWidget(putTextBtn);
    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;
    temp.open();
    QByteArray d ("11212121212\n");
    temp.write(d) ;
    temp.close();
    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;
    files.append(url);
    mime->setUrls(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");
    return;
    }

        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";
    }
    @

    main
    @

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

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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bootchk
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cmazieri
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cmazieri
          wrote on last edited by
          #4

          Hi Bootchk you' re right,

          In N9 device it works as expected,

          I thought it would work in emulators.

          Thank you

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved