Results 1 to 3 of 3

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

  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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,714
    Thanks
    259
    Thanked 759 Times in 749 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

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

    If you want inter-operability with non-Qt apps, like MS Paint, then you need to convert your image into one of the "standard" MIME types, like image/jpg or image/bmp. There is a complete list here. This will probably require saving your QImage into one of these image types before pasting it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3

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

    Quote Originally Posted by d_stranz View Post
    If you want inter-operability with non-Qt apps, like MS Paint, then you need to convert your image into one of the "standard" MIME types, like image/jpg or image/bmp. There is a complete list here. This will probably require saving your QImage into one of these image types before pasting it.
    When I press the Print-Screen key to take a screenshot, the only format I got is "application/x-qt-image". I do not know what the standard mime is for the image in the clipboard, how can I convert to a standard mime type?

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.