Using Qt's drawText-functionality without an QApplication-Instance
-
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 -
Hi,
AFAIK, no, but what would be the problem of having a QApplication in your library ?
-
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.
-
[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