[Qt-interest] QClipboard with jpeg files, question

Sudheesh K sudheesh at softjin.com
Sun Jul 24 05:46:16 CEST 2011


Hi Harri, 


Suggest use the following function. 


1. void QClipboard::setImage ( const QImage & image , Mode mode = Clipboard ) 
2. Have a look at (Drag and Drop - help topic from assistant) qthelp://com.trolltech.qt.453/qdoc/dnd.html 


Regards, 
Sudheesh 
----- Original Message -----

From: "Harri Pasanen" <grego at mpaja.com> 
To: qt-interest at qt.nokia.com 
Sent: Saturday, July 23, 2011 6:00:50 PM 
Subject: [Qt-interest] QClipboard with jpeg files, question 

Hi, 

Using Qt 4.7.3 
I tried to put a jpeg to QClipboard in the hope that I could just paste it 
from there to email. Unfortunately it doesn't work for me: 


The following snippet works fine and seems to put a png to clipboard (on 
linux): 

QClipboard *clipboard = QApplication::clipboard(); 
clipboard->setPixmap(pic); 


I can the paste this to KMail for instance. 

As pngs are big, I figured I would try turning it to jpeg, the code being: 


QByteArray ba; 
QFile jpgfile(filename); 
jpgfile.open(QIODevice::ReadOnly); 
ba = jpgfile.readAll(); 
jpgfile.close(); 
QMimeData *md = new QMimeData(); 
QString imgtype = "image/jpeg"; 
md->setData(imgtype, ba); 
QClipboard *clipboard = QApplication::clipboard(); 
clipboard->setMimeData(md); 

(I saved the pixmap as jpeg file to check the jpeg is ok) 

But that does not seem to work, I still get a png from clipboard.... 

It's a bit unclear to me at what level this conversion is done, Qt or OS or 
...? 


Any hints? 

Thanks, 

Harri 
http://mpaja.com/ 
_______________________________________________ 
Qt-interest mailing list 
Qt-interest at qt.nokia.com 
http://lists.qt.nokia.com/mailman/listinfo/qt-interest 



More information about the Qt-interest-old mailing list