Results 1 to 3 of 3

Thread: URGENT HELP Code128 barcode printing

  1. #1
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default URGENT HELP Code128 barcode printing

    I am having a major issue printing a readable barcode from QT on an epson M-T500 printer thermal receipt printer.

    i am using the font from http://www.dafont.com/code-128.font

    It prints th ebarcode but somehow its not printing the correct order

    I even tried to hardcode the char with ascii code still does not work.

    Any help will be much appreciated.

    The Barcode text: MHB-6TG-6TG-GGHJ

    My sample code:

    Qt Code:
    1. QPrinter printer;
    2. QPainter painter;
    3. painter.begin(&printer);
    4. double scaleFactor;
    5. scaleFactor = 1.0;
    6. QFont barcodefont = QFont("Code128", 32, QFont::Normal);
    7. barcodefont.setLetterSpacing(QFont::AbsoluteSpacing,1.0);
    8. painter.setFont(barcodefont);
    9. char mytext[20];
    10.  
    11. mytext[0]= 204;
    12. mytext[1]=77;
    13. mytext[2]=72;
    14. mytext[3]=66;
    15. mytext[4]=45;
    16. mytext[5]=54;
    17. mytext[6]=84;
    18. mytext[7]=71;
    19. mytext[8]=45;
    20. mytext[9]=54;
    21. mytext[0]=84;
    22. mytext[11]=71;
    23. mytext[12]=45;
    24. mytext[13]=71;
    25. mytext[14]=71;
    26. mytext[15]=72;
    27. mytext[16]=74;
    28. mytext[17]=104;
    29. mytext[18]=206;
    30. mytext[19]=0;
    31. qDebug() << mytext;
    32. painter.drawText(-30, 370,mytext);
    33. painter.end();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: URGENT HELP Code128 barcode printing

    I assume the '\xCC' and '\xCE' characters are a start and end marker. Your array index 10 is mistyped, and I have converted it to a QByteArray. This code:
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. // QPrinter printer;
    9. // printer.setOutputFormat(QPrinter::PdfFormat);
    10. // printer.setOutputFileName("test.pdf");
    11.  
    12. QImage image(640, 100, QImage::Format_Mono);
    13. image.fill(1);
    14.  
    15. QPainter painter;
    16. painter.begin(&image);
    17.  
    18. QFont barcodefont = QFont("code128", 32, QFont::Normal);
    19. barcodefont.setLetterSpacing(QFont::AbsoluteSpacing,10.0); //deliberately spread out
    20. painter.setFont(barcodefont);
    21.  
    22. QByteArray mytext("\xccMHB-6TG-6TG-GGHJ\xce");
    23. qDebug() << mytext;
    24. painter.drawText(10, 90, mytext);
    25. painter.end();
    26.  
    27. image.save("test.png");
    28.  
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    produces this output (this is the PNG, but the PDF looks the same):
    test.png

    The characters look good here.

  3. The following user says thank you to ChrisW67 for this useful post:

    georgeky (26th July 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: URGENT HELP Code128 barcode printing

    Thank You soo much for your help :-) Worked like a charm

Similar Threads

  1. Code128 barcode
    By wirasto in forum Qt-based Software
    Replies: 3
    Last Post: 8th August 2015, 03:12
  2. Replies: 2
    Last Post: 22nd September 2014, 04:25
  3. drawing barcode with GNU Barcode
    By Feoran in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2010, 07:55
  4. Problem in printing barcode
    By alferjaani in forum Qt Programming
    Replies: 0
    Last Post: 21st July 2010, 18:33
  5. [URGENT] Weird compile error [URGENT]
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 24th May 2008, 23:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.