arsdever
arsdever

Reputation: 1262

How to implement drag&drop between 2 applications?

I'm trying to create an application, which will communicate through QLocalServer / QLocalSocket. The server name passing mechanism I planned to implement using the drag&drop mechanism. The mechanism is like the following:

I have implemented some code, but it seems, that drag&drop between applications make some changes in mimeData object. Here are code snippets and the result I have got:

mouseMoveEvent(QMouseEvent* event)
{
    if (!__drag_options.__drag_started)
        return;

    if (distance(__drag_options.__drag_started_position, event->pos()) < DRAG_DISTANCE)
        return;

    QDrag drag(this);
    QMimeData* mimeData = new QMimeData;
    mimeData->setData("type", "pin");
    mimeData->setData("address", __address);
    drag.setMimeData(mimeData);
    drag.exec(Qt::MoveAction);
}

dropEvent(QDropEvent* event)
{
    qDebug() << "dropEvent " << event->mimeData()->formats();
    const QMimeData* mime = event->mimeData();
    QString serverName = mime->data("pin_name");
    __socket->connectToServer(serverName);
}

and the result is

dragEnterEvent ("application/x-qt-windows-mime;value=\"type\"", "application/x-qt-windows-mime;value=\"address\"")

As you can see there's no mime named "address".

Any suggestions on how to get to the target?

Upvotes: 0

Views: 368

Answers (1)

Martin Hennings
Martin Hennings

Reputation: 16846

I suggest you use a standard mime type like json or application/json (and send your data encoded in JSON), or XML, or ...

If you use a custom mime type, you have to live with the fact that Qt changes that mime type so it is more standard conformant.

As long as you stay within one application, your mime types won't be touched.

As soon as you drag from one application to another, you need the clipboard or such of the platform. (If I recall correctly, Windows only supports some of the possible mime types.)

Upvotes: 1

Related Questions