PDA

View Full Version : Drag outlook attachment to Qt Application



superpacko
21st November 2011, 20:04
Im testing my drag&drop classes, so far im able to drop files, text and gmail attachments into my application, BUT when i try to drag an attachment from an Outlook email, i get nothing.



void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << "Format: " << event->format() ;
qDebug() << "Supported formtas: " << event->mimeData()->formats().join(",");

if (event->mimeData()->hasHtml() ||
event->mimeData()->hasText() ||
event->mimeData()->hasUrls() ||
event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"Shell IDList Array\"") ||
event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileName\"") ||
event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileNameW\"") ||
event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileGroupDescriptorW\""))
{
event->acceptProposedAction();
activateWindowDrop();
}
}


here's what i get when i drag the attachment:
Format: application/x-qt-windows-mime;value="FileGroupDescriptorW"
Supported formtas: "application/x-qt-windows-mime;value="FileGroupDescriptorW",application/x-qt-windows-mime;value="FileGroupDescriptor",application/x-qt-windows-mime;value="RenPrivateItem",application/x-qt-windows-mime;value="FileContents""

I thought that the local url of the attachment would be stored in the getUrls(), so i tried:


void MainWindow::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasText())
qDebug() << "Text: " << event->mimeData()->text();
else
{
foreach (QUrl url, event->mimeData()->urls())
qDebug() << url.toLocalFile();// empty

QByteArray data = event->mimeData()->data("FileGroupDescriptorW");
qDebug() << QString::fromUtf16((ushort*)data.data(), data.size() / 2); // "r"
qDebug() = event->mimeData->data("FileName");//empty
qDebug() = event->mimeData->data("FileContents");//empty
qDebug() = event->mimeData->data("RenPrivateItem");//empty
}
}


Anyone knows how to do this? i've tried draggin a .RAR file, as well as a.DOCX, and is the same.

Thanks!

superpacko
24th November 2011, 15:23
OK, so i found the solution.
The kind of mime format that i get when draggin an outlook attachment is "application/x-qt-windows-mime;value="FileGroupDescriptorW""
I have no url or filename, but i can get the content of the attachment via event->mimeData->data("FileContents");
Then i write that into a QFile and i am ready to go and do something with that file.

Bye.