(self)
This slot function is called when the "Load Image From File..."
        button is pressed on the firs Dialog process.  First, it tests whether
        the process is already connected to a shared memory segment and, if so,
        detaches from that segment.  This ensures that we always start the
        example from the beginning if we run it multiple times with the same
        two Dialog processes.  After detaching from an existing shared memory
        segment, the user is prompted to select an image file.  The selected
        file is loaded into a QImage.  The QImage is displayed in the Dialog
        and streamed into a QBuffer with a QDataStream.  Next, it gets a new
        shared memory segment from the system big enough to hold the image data
        in the QBuffer, and it locks the segment to prevent the second Dialog
        process from accessing it.  Then it copies the image from the QBuffer
        into the shared memory segment.  Finally, it unlocks the shared memory
        segment so the second Dialog process can access it.  After self
        function runs, the user is expected to press the "Load Image from
        Shared Memory" button on the second Dialog process.
This slot function is called when the "Load Image From File..."
        button is pressed on the firs Dialog process.  First, it tests whether
        the process is already connected to a shared memory segment and, if so,
        detaches from that segment.  This ensures that we always start the
        example from the beginning if we run it multiple times with the same
        two Dialog processes.  After detaching from an existing shared memory
        segment, the user is prompted to select an image file.  The selected
        file is loaded into a QImage.  The QImage is displayed in the Dialog
        and streamed into a QBuffer with a QDataStream.  Next, it gets a new
        shared memory segment from the system big enough to hold the image data
        in the QBuffer, and it locks the segment to prevent the second Dialog
        process from accessing it.  Then it copies the image from the QBuffer
        into the shared memory segment.  Finally, it unlocks the shared memory
        segment so the second Dialog process can access it.  After self
        function runs, the user is expected to press the "Load Image from
        Shared Memory" button on the second Dialog process.
This slot function is called when the Load Image From File ... button is pressed on the firs Dialog process . First it tests whether the process is already connected to a shared memory segment and if so detaches from that segment . This ensures that we always start the example from the beginning if we run it multiple times with the same two Dialog processes . After detaching from an existing shared memory segment the user is prompted to select an image file . The selected file is loaded into a QImage . The QImage is displayed in the Dialog and streamed into a QBuffer with a QDataStream . Next it gets a new shared memory segment from the system big enough to hold the image data in the QBuffer and it locks the segment to prevent the second Dialog process from accessing it . Then it copies the image from the QBuffer into the shared memory segment . Finally it unlocks the shared memory segment so the second Dialog process can access it . After self function runs the user is expected to press the Load Image from Shared Memory button on the second Dialog process .
def loadFromFile(self):
        """ This slot function is called when the "Load Image From File..."
        button is pressed on the firs Dialog process.  First, it tests whether
        the process is already connected to a shared memory segment and, if so,
        detaches from that segment.  This ensures that we always start the
        example from the beginning if we run it multiple times with the same
        two Dialog processes.  After detaching from an existing shared memory
        segment, the user is prompted to select an image file.  The selected
        file is loaded into a QImage.  The QImage is displayed in the Dialog
        and streamed into a QBuffer with a QDataStream.  Next, it gets a new
        shared memory segment from the system big enough to hold the image data
        in the QBuffer, and it locks the segment to prevent the second Dialog
        process from accessing it.  Then it copies the image from the QBuffer
        into the shared memory segment.  Finally, it unlocks the shared memory
        segment so the second Dialog process can access it.  After self
        function runs, the user is expected to press the "Load Image from
        Shared Memory" button on the second Dialog process.
        """

        if self.sharedMemory.isAttached():
            self.detach()

        self.ui.label.setText("Select an image file")
        fileName, _ = QFileDialog.getOpenFileName(self, None, None,
                "Images (*.png *.xpm *.jpg)")
        image = QImage()
        if not image.load(fileName):
            self.ui.label.setText(
                    "Selected file is not an image, please select another.")
            return

        self.ui.label.setPixmap(QPixmap.fromImage(image))

        # Load into shared memory.
        buf = QBuffer()
        buf.open(QBuffer.ReadWrite)
        out = QDataStream(buf)
        out << image
        size = buf.size()

        if not self.sharedMemory.create(size):
            self.ui.label.setText("Unable to create shared memory segment.")
            return

        size = min(self.sharedMemory.size(), size)
        self.sharedMemory.lock()

        # Copy image data from buf into shared memory area.
        self.sharedMemory.data()[:size] = buf.data()[:size]
        self.sharedMemory.unlock()
def loadFromFile ( self ) : if self . sharedMemory . isAttached ( ) : self . detach ( ) self . ui . label . setText ( "Select an image file" ) fileName , _ = QFileDialog . getOpenFileName ( self , None , None , "Images (*.png *.xpm *.jpg)" ) image = QImage ( ) if not image . load ( fileName ) : self . ui . label . setText ( "Selected file is not an image, please select another." ) return self . ui . label . setPixmap ( QPixmap . fromImage ( image ) ) # Load into shared memory. buf = QBuffer ( ) buf . open ( QBuffer . ReadWrite ) out = QDataStream ( buf ) out << image size = buf . size ( ) if not self . sharedMemory . create ( size ) : self . ui . label . setText ( "Unable to create shared memory segment." ) return size = min ( self . sharedMemory . size ( ) , size ) self . sharedMemory . lock ( ) # Copy image data from buf into shared memory area. self . sharedMemory . data ( ) [ : size ] = buf . data ( ) [ : size ] self . sharedMemory . unlock ( )