Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Lifetime of QByteArray references when constructing QRawFont using loadFromData()
Qt 6.12 LTS is out! See what's new in the release blog

Lifetime of QByteArray references when constructing QRawFont using loadFromData()

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 230 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    PolarFox
    wrote last edited by
    #1

    Does Qt make any guarantees about the use and copying of QByteArray objects passed to QRawFont::loadFromData(), and how does this apply to a QByteArray that doesn't own the memory it points to (constructed via QByteArray::fromRawData)?

    I am working on an application that loads the font bytes in another language and gives a pointer to it to Qt across the FFI boundary to avoid making full copy of the font data. I need to know if Qt will attempt to access that memory even after the QRawFont object has been freed, and I couldn't find anything in the documentation about it.

    Will destroying the QRawFont object be enough to ensure that the underlying memory is safe to be freed?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      You should not pass any object anywhere with a shorter lifetime than where you pass the object too except it is stated otherwise. Therefore make sure the data referenced by QByteArray::fromRawDate() outlifes the QFontEngine or don't use fromRawDate() here.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PolarFox
        wrote last edited by
        #3

        How long does a QFontEngine live for, and if it lives longer than the QRawFont, can I remove fonts from it? I want to make sure that when a font is no longer needed, I can safely free the data that the QByteArray references, so that I don't keep an unused font in memory.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote last edited by
          #4

          If you delete the font the underlying engine is also deleted. But why bother with these few bytes you might save when using fromRawData. It's not worth the trouble.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • P Offline
            P Offline
            PolarFox
            wrote last edited by
            #5

            If the font engine is destroyed when the QRawFont is, and the font engine isn't shared between different fonts, then it should be fine.
            And unfortunately for me, I don't know what fonts or how many fonts might be loaded, so I want to prevent two copies of the font data existing at once.

            Thanks for the help though!

            1 Reply Last reply
            0
            • P PolarFox has marked this topic as solved

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved