KKyang
KKyang

Reputation: 45

Sending image between two Qt exe

I'm trying to make my applications able to send images to each other without saving it.

I've found there's several ways to achieve the goal. Including:

QSharedMemory

QLocalServer

QProcess

I would like to use QSharedMemory but I don't know how to send a signal from one to another to make a request. The following example shows how to use QShareMemory but no sending signal.

http://qt-project.org/doc/qt-4.8/ipc-sharedmemory.html

If I choose to sue QLocalServer, that means I have to communicate through network(?). I don't know if this is a good idea or not cause image files can be huge.

If I choose to use QProcess, I don't know how to make a connection between two apps if they are open separately by directly double click the exe.

Any suggestions? Thanks very much!

Update

I try to use QLocalSocket but I'm stuck sending image to another application cause stuck in the bytesAvailable() while loop.

QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_3);
if(client_status == 0)
{
    out << m_message;
}
else if(client_status == 1)
{
    out << m_image;
}
out.device()->seek(0);
m_socket->write(block);
m_socket->flush();

The program stucks here.

while (clientConnection->bytesAvailable() < (int)dataSize)

I try to set the size of the dataSize equal to block.size() doesn't work.

Upvotes: 0

Views: 647

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27611

I would like to use QSharedMemory

Why do you have a desire to do this?

If the applications are on the same machine, then I suggest using QLocalServer. Functionally it may appear to require a network, as the concepts are similar to QTcpSocket, but in reality, no network is required. As the docs state for QLocalSocket

On Windows this is a named pipe and on Unix this is a local domain socket.

If applications are running on different machines, then I suggest using QTcpServer, which has a similar functional interface as QLocalServer and QLocalSocket.

QProcess is not the solution here. Whilst the docs state "The QProcess class is used to start external programs and to communicate with them" the communication is referring to controlling the application, sending input and receiving its output and error streams.

Upvotes: 2

Related Questions