I would like to create and write an image to the memory in such a way that other processes are able to read it. The goal is to have a Python script create some graph using matplotlib.pyplot, write it to the memory as a png file and then have a Qt application written in C++ or Python read that image and be able to render it in it's own window using the capabilities of Qt. I would specifically want to avoid saving the image to the hard disk.
IF I was to use the hard disk as a bridge between the two processes, my code would look something like this:
Python script to create the image and save it as a png:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
plt.plot(x, y, marker = "o", linestyle = "-")
plt.savefig("my_graph.png")
Qt Application written in Python that has a GraphWidget class to render it:
class GraphWidget(QWidget):
def __init__(self, parent : parent : Optional[QWidget] = None) -> None:
super().__init__(parent)
def paintEvent(self, event):
painter = QPainter(self)
painter.drawPixmap(0, 0, QPixmap("./my_graph.png"))
In this example, the Qt application is written in Python because at the time of writing this it is more convenient to provide an example in Python (I will update the question with C++ code as soon as possible), but the point is the same. This code uses the hard disk as a means to share the image between the two processes. Is there a way to achieve the same result without utilizing the disk and writing the image straight to memory using Python and reading it from the memory with C++?
If this can't be done by utilizing the memory, can you suggest any alternatives to achieve the same result without using the hard disk?
I am a beginner programmer and this is my first question in years, so any help would be appreciated that could expand my view of possible solutions.