pyQt6 - AttributeError: 'QByteArray' object has no attribute 'setRawData'
-
The documentation indicates the presence of the setDataRaw function in QByteArray class. But on inspection, the method is absent and on execution I get the message quoted in object . I'm using PyQt6 version 6.5.0 and PyQt6.sip version 13.5.1. So what are my options? Waiting for setDataRaw to be re-included in PyQt6?
Cordialy,
Pierre Lepage -
The documentation indicates the presence of the setDataRaw function in QByteArray class. But on inspection, the method is absent and on execution I get the message quoted in object . I'm using PyQt6 version 6.5.0 and PyQt6.sip version 13.5.1. So what are my options? Waiting for setDataRaw to be re-included in PyQt6?
Cordialy,
Pierre LepageHi,
Can you explain your use of setRawData in the Python context ?
-
@SGaist
Hi,I have two Qt applications independent of each other (two processes in Kubuntu). The second application needs to know the state of the window of the first application i.e. iconify in the taskbar (minimized) or visible on the screen (maximized). I summarize this state in a boolean variable. The transfer of value is done by a QSharedMemory object.
The code in the first application (the one that writes its window state to shared memory).
def _write_to_shared_memory(self, value: bool): """Helper function""" self.shared_memory.lock() _memory_pointer = self.shared_memory.data() byte_array: QByteArray = QByteArray(self.__size_of_shared_memory, b'\x00') byte_array.setRawData(bytes(_memory_pointer), self.__size_of_shared_memory) byte_array[0] = int(value) self.shared_memory.unlock()
Note
self.__size_of_shared_memory = bool().sizeof()
This gives 24 bytes.The code in the second application (the one that reads the boolean state from shared memory).
def _read_from_shared_memory(self): """Helper function""" self.shared_memory.lock() _memory_pointer = self.shared_memory.data() byte_array: QByteArray = QByteArray(self.__size_of_shared_memory, b'\x00') self.is_main_window_minimized = bool(byte_array[0]) self.hide_spinner() self.shared_memory.unlock()
-
@SGaist
Hi,
I solved my problem in the following way:From the first application:
def _write_to_shared_memory(self, value: bool): """Helper function""" self.shared_memory.lock() my_bool = bytearray(24) my_bool[0] = 1 if value else 0 self.shared_memory.data()[:24] = my_bool self.shared_memory.unlock()
From the second application:
def _read_from_shared_memory(self): """Helper function""" self.shared_memory.lock() _memory_pointer: sip.voidptr = self.shared_memory.data() _my_bool = bytearray(_memory_pointer[:24]) self.is_window_minimized = _my_bool[0] self.hide_spinner() self.shared_memory.unlock()
Well, a single byte would suffice. The 24 byte number comes from the size of a Boolean in Python. But a single byte would suffice.