Results 1 to 3 of 3

Thread: How to save the image in clipboard in variable and restore it to clipboard later?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default How to save the image in clipboard in variable and restore it to clipboard later?

    I connect a slot to the dataChanged signal of QClipboard to store the image in the clipboard to a variable mimedata(reference):
    Qt Code:
    1. void MyWin::clipboardDataChanged()
    2. {
    3. const QMimeData * m=QApplication::clipboard()->mimeData();
    4. mimedata = new QMimeData();
    5.  
    6. foreach(QString format, m->formats())
    7. {
    8. QByteArray data = m->data(format);
    9. if(format.startsWith("application/x-qt"))
    10. {
    11. int index1 = format.indexOf('"') + 1;
    12. int index2 = format.indexOf('"', index1);
    13. format = format.mid(index1, index2 - index1);
    14. }
    15. mimedata->setData(format, data);
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    And restore mimedata to clipboard as follows:
    Qt Code:
    1. void MyWin::onrestore()
    2. {
    3. QApplication::clipboard()->setMimeData(mimedata);
    4. }
    To copy to clipboard, switch view to plain text mode 
    However, the data set to the clipboard seems corrupted. If I paste from the clipboard to Paint, it says "The information on the Clipboard can't be inserted into Paint." I printed the format of the data in the clipboard, i.e., "application/x-qt-image". So I think it is not a format that is supported by other applications. Is this a bug of Qt?
    Last edited by qtcentre2019; 19th January 2020 at 12:44.

Similar Threads

  1. QtCreator unable to copy to the clipboard...
    By squimmy in forum Qt Tools
    Replies: 4
    Last Post: 25th December 2012, 13:53
  2. copy - paste clipboard contents
    By viswanathan in forum Newbie
    Replies: 1
    Last Post: 8th January 2010, 13:10
  3. How to copy QTableWidget to Clipboard
    By ranna in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2008, 16:47
  4. Help needed re: clipboard detection
    By sdfisher in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 01:45
  5. QApplication::clipboard not read textCursor cut
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2007, 23:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.