Results 1 to 6 of 6

Thread: Interface printer with QT Application

  1. #1
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Interface printer with QT Application

    Dear All,

    I want to print the form image on to thermal printer interfaced to its serial port.

    I am able to save the image on to a file.

    QPixmap pixmap(this->size());
    this->render(&pixmap);
    pixmap.save("myfile.pgm", "PGM");
    The thermal printer interfaced is capable to print the image with the following command from serial port.

    ESC # print Logo.
    ESC # nW nH Data String
    i.e in hex format
    <1Bh> <23h> <n1h> <n2h> <Hex String>

    [Description]
    Prints Logo/Image in the predefined area
    Spacing: n x 0.125mm (1 dot size)
    [nW x nH]: Print Area Size (Width x Height) (this will also equal to total number of bytes.
    nW = Number of Bytes to be Printer per line
    Max: 48 bytes
    nH = Total Bytes / Number of Bytes Per line
    Max: 255 bytes

    can any one let me know the image format which I can use so that I execute the print command directly.

    Or I have use a library to convert the standard file format to a Hex data.

    Thanks in Advance.
    ratheendran

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Interface printer with QT Application

    Why doesn't you use QPrinter and QPrintDialog?

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

    Ratheendrans (1st August 2011)

  4. #3
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Interface printer with QT Application

    Thanks for your response.

    My application is for embedded linux and the interface printer needs image data written to serial port. so my Idea is to take the image of the form and write its hex data to serial port

    I am not sure how ' QPrinter and QPrintDialog' is use-full. can you please eloborate on how this can be used in my application.

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Interface printer with QT Application

    Print Area Size (Width x Height) (this will also equal to total number of bytes.
    In order to get pixel data, you need to convert QPixmap to QImage, the quoted text indicates that you are forced to use 8 bits per pixel, this implies QImage::Format_Indexed8 format (I dont see any other 8-bit formats). You can get access to pixel data using QImage::constBits method.

  6. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Interface printer with QT Application

    I would say this printer is black and withe (no gray scale). He quote documentation "nW = Number of Bytes to be Printer per line Max: 48 bytes" so I assume one byte is 8 pixels.
    probably this is a printer like in cash register (48 pixels per line is to small value to present any useful information).
    I agree that he should do conversion to QImage but using format QImage::Format_Mono.
    So code would look more or less like this:
    Qt Code:
    1. Q_ASSSERT(pixmap.depth()==1);
    2. const QImage image = pixmap.toImage();
    3. QByteArray buffer;
    4. buffer.append('\x1B');
    5. buffer.append('\x23');
    6.  
    7. int lineSize = (image.width()+7)/8;
    8. buffer.append((char)lineSize);
    9. buffer.append((char)image.hieht());
    10. for(int i=0; i<image.hieht(); ++i)
    11. buffer.append(image.scanLine(i), lineSize);
    12.  
    13. QFile file("com1:"); // serial port name on device on embedded system (here used Windows CE)
    14. if (!file.open(QIODevice::WriteOnly))
    15. return;
    16. file.write(buffer);
    17. file.waitForBytesWritten(3000);// wait max 3 seconds
    18. file.close();
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Interface printer with QT Application

    48 pixels per line is to small value to present any useful information
    I don't agree with this one, but probably you are right with the image format.

Similar Threads

  1. Replies: 1
    Last Post: 8th October 2010, 11:38
  2. Replies: 1
    Last Post: 9th November 2009, 09:27
  3. Mouse tracking outside the application interface
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 2nd May 2009, 06:44
  4. run a console application through a gui interface
    By gurinder in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2008, 12:52
  5. No printer installed..?
    By Cutey in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2007, 11:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.