[Qt-interest] QMimeData::setHtml crash

Joshua Grauman jnfo-c at grauman.com
Sat Jan 30 21:09:01 CET 2010


Hello,

Could someone verify how QClipboard/QMimeData works. I think I've figured 
out my problem, but want to make sure I understand.

When I call clipboard->setMimeData(mimedata); the docs say ownership of 
the data is transferred to the clipboard. Does this mean that the 
clipboard is now responsible to delete the mimedata object and so I don't 
have to? Does this also imply that each successive time I call 
clipboard->setMimeData(mimedata); I need to create a new QMimeData object 
to send to it? Thanks!

Previously, I had been reusing the same QMimeData object, sending the same 
one to setMimeData, but I'm guessing that the clipboard deleted my object, 
so calling setHtml on it caused the crash. Sound right?

void myClass::shortcutCopySelection(void)
{
   QString selectionText;
   if(!mimedata)
     mimedata=new QMimeData;
   //code to set selectionText here,
   mimedata->setHtml(selectionText); //this line is crashing
   clipboard->setMimeData(mimedata);
}



More information about the Qt-interest-old mailing list