Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using Qt's drawText-functionality without an QApplication-Instance
Qt 6.11 is out! See what's new in the release blog

Using Qt's drawText-functionality without an QApplication-Instance

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k 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
    plaxik
    wrote on last edited by
    #1

    Hi,

    I want to print unicode text in an image.

    Using QApplication, QPainter and drawText(), this works well. However, since my code is part of a class library, there is no QApplication I could use in order to write in the image.

    Is there any other way or workaround to write/burn/put text into an image (QImage) in Qt without instantiating QApplication?

    Best,
    plaxik

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK, no, but what would be the problem of having a QApplication in your library ?

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

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

        Hi,

        you have a great response time. Thx for your reply, although it's not a "yes".

        As far as I know, there can only be one QApplication instance within a program. And it is common that, in my case, for example, the calling application provides a QApplication instance for the library such that the library functions can use it, for example, to put text into an image using drawText().

        However, my library is required to be conformant with Qt and non-Qt applications. That means, i'd also like my library to be linked by programs which do not know Qt. Therefore, my interface does not support any Qt components as arguments.

        For sure, I could just instantiate my own QApplication object within my library. However, if a Qt application is linking my library which already instantiated a QApplication object for its own purposes I do have a problem, don't I?

        Sorry for this confusing description of my problem. Hope you got my point.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          [quote author="plaxik" date="1413879532"]For sure, I could just instantiate my own QApplication object within my library. However, if a Qt application is linking my library which already instantiated a QApplication object for its own purposes I do have a problem, don’t I?[/quote]

          Exactly.
          Nevertheless you can check if there is already a QApplication instantiated. If not create your own.
          Only drawback is that pointer remains as a dangling pointer (when you decide to delete your own created application)
          So not a very clean solution

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

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