Draw text in an image without a QApplication

  • To draw text in an image, I usually use a QPainter. This method requires that a QApplication be available. However, I am trying to write this function in a library so that it can be called from a Qt program or from a non Qt program (just using some bits of Qt as library functions, rather than necessarily using it for a GUI).

    Is there a way to do something like this:

    @#include <QApplication>

    #include "form.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QPixmap pixmap(20, 20);
    QColor red(255,0,0);

    QPainter painter(&pixmap);

    QFont font("", 6); // arbitrary (default) font, size 2

    painter.drawText(QPointF(10,10), "test"); // bottom left corner of the text seems to start at this point

    return 0;

    but without a QApplication?



  • You can try to instantiate QApplication instance in the thread in your dll and do the work there, maybe it will work.(works for QNAM for example). But in general it is not allowed and unsupported.

Log in to reply