Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. pyQt6 - AttributeError: 'QByteArray' object has no attribute 'setRawData'
QtWS25 Last Chance

pyQt6 - AttributeError: 'QByteArray' object has no attribute 'setRawData'

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 515 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tenderbread
    wrote on 13 May 2023, 17:35 last edited by
    #1

    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

    S 1 Reply Last reply 13 May 2023, 18:19
    0
    • T Tenderbread
      13 May 2023, 17:35

      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

      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 May 2023, 18:19 last edited by
      #2

      Hi,

      Can you explain your use of setRawData in the Python context ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 2 Replies Last reply 13 May 2023, 23:19
      0
      • S SGaist
        13 May 2023, 18:19

        Hi,

        Can you explain your use of setRawData in the Python context ?

        T Offline
        T Offline
        Tenderbread
        wrote on 13 May 2023, 23:19 last edited by Tenderbread
        #3

        @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()
        
        1 Reply Last reply
        0
        • S SGaist
          13 May 2023, 18:19

          Hi,

          Can you explain your use of setRawData in the Python context ?

          T Offline
          T Offline
          Tenderbread
          wrote on 14 May 2023, 01:10 last edited by
          #4

          @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.

          1 Reply Last reply
          0

          2/4

          13 May 2023, 18:19

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved