Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Barcode generation on Windows and Linux [Solved]



  • Hi all,
    I must develop an application that print some barcode (code 39) .
    The application should run on windows and linux.

    I know that on Windows it's possible using barcode font (for example IDAutomationHC39M) but what on Linux?

    Are there some Qt/C++ API that allow barcode generation?



  • "I think this one can be used for your case too: ":http://www.qtcentre.org/wiki/index.php?title=EAN-13_Barcode_class



  • [quote author="Eddy" date="1311416375"]"I think this one can be used for your case too: ":http://www.qtcentre.org/wiki/index.php?title=EAN-13_Barcode_class[/quote]

    Good link, thanks.
    For me it should be better the "Code 39".

    Now I found a way to install IDAutomationHC39M in my Slackware Linux so I can print with it both on linux and windows.

    I actually use the font this way:
    @
    ...
    ...
    painter.setFont(QFont("IDAutomationHC39M", 30));
    painter.drawText(rect(), Qt::AlignCenter, "123456789");
    ...
    @

    Is it possible to "embed" the font in my Qt application to avoid font installation on every system I use it?



  • I've never done it with a font, but you could try to add the file in a qrc file using the resource system.

    I hope it works.

    Edit : try to use it like this :
    @
    SetFont(":/fonts/yourfont");

    @



  • [quote author="Eddy" date="1311417465"]I've never done it with a font, but you could try to add the file in a qrc file using the resource system.

    I hope it works.

    Edit : try to use it like this :
    @
    SetFont(":/fonts/yourfont");

    @[/quote]

    It doesn't works.
    I think SetFont() doesn't accept a filename.



  • Try the following to add your font to your application :
    @int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]@
    (please read the notes in the docs for linux)
    Use it like this :

    @QFontDatabase fontDatabase;
    fontDatabase.addApplicationFont(":/fonts/yourfont");@

    And then use setFont



  • Here is an interesting SDK for you: "Barcode SDK":http://www.leadtools.com/sdk/barcode/



  • [quote author="Eddy" date="1311524605"]Try the following to add your font to your application :
    @int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]@
    (please read the notes in the docs for linux)
    Use it like this :

    @QFontDatabase fontDatabase;
    fontDatabase.addApplicationFont(":/fonts/yourfont");@

    And then use setFont
    [/quote]

    Thanks a lot Eddy, it works!

    I tried under Linux (Slackware 13.37) and it works without problem. I don't know why the documentation note say that:
    @
    Adding application fonts on Unix/X11 platforms without fontconfig is currently not supported.
    @



  • You're welcome. I'm glad it works for you.

    Maybe the note in the docs is from ancient times when it didn't work ;)

    Have fun.



  • I only tried those which support Code 39 barcode generating using .NET app. It support C++, C#. You may search online.


Log in to reply