I used QUdpSocket to transfer path for opening files like this
QSocketListener::QSocketListener()
{
connect(socket_, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
}
void QSocketListener
::SendPath(QString filePath
)//Send Data {
socket_->disconnect();
socket_
->writeDatagram
(filePath.
toUtf8(),
QHostAddress::LocalHost,
40002 );
}
void QSocketListener::readPendingDatagrams()
{
datagram.resize(socket_->pendingDatagramSize());
socket_->readDatagram(datagram.data(), datagram.size());
emit openFile(path);
}
QSocketListener::QSocketListener()
: QObject(parent)
{
socket_ = new QUdpSocket();
socket_->bind(QHostAddress::LocalHost, 40002);
connect(socket_, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
}
void QSocketListener::SendPath(QString filePath)//Send Data
{
socket_->disconnect();
socket_->writeDatagram(filePath.toUtf8(), QHostAddress::LocalHost, 40002 );
}
void QSocketListener::readPendingDatagrams()
{
QByteArray datagram;
datagram.resize(socket_->pendingDatagramSize());
socket_->readDatagram(datagram.data(), datagram.size());
QString path = datagram;
emit openFile(path);
}
To copy to clipboard, switch view to plain text mode
I hope it helps
Bookmarks