Important: Please read the Qt Code of Conduct -

[Solved] How to send control command to POS printer?

  • Hi,

    I am creating an application which prints text through a POS printer.

    @#include "lanprinterui.h"
    #include "ui_lanprinterui.h"

    LanPrinterUI::LanPrinterUI(QWidget *parent) :
    ui(new Ui::LanPrinterUI)

    m_TextInput = ui->textEdit;
    m_pSocket   = new QTcpSocket();
    m_pSocket->connectToHost("", 9100);
    m_ConnectStatus = true;
    QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(print()));


    delete ui;
    delete m_pSocket;

    void LanPrinterUI::print()
    const int Timeout = 5 * 1000;

    if (!m_ConnectStatus)
        m_pSocket->connectToHost("", 9100);
    if (!m_pSocket->waitForConnected(Timeout))
        //sent error
        qDebug ("error in waitForConnected()");
        qDebug (qPrintable(m_pSocket->errorString()));
        m_ConnectStatus = false;
    m_ConnectStatus = true;
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out << m_TextInput->toPlainText();
    out << '\n';


    The prints works fine. But for POS printer there are control commands to do certain functions like : paper cut, cashdraw open etc.. For eg:

    Function: Partial cut
    ASCII-------> ESC i
    Hex --------> 1B 69
    Decimal-----> 27 105

    When I try to send command 27 105 it just prints on paper.. I'm not exactly sure how to send it... Can someone suggest how to write to the socket...

  • I got the solution from a different forum..

    out << "\n\x1Bi";

    Hope this would help someone else...

  • @Abin hello albin ..can you please send me this full code...because im facing problem with printing using pos printer

  • @najeeb I second this. It would be great to download some source files of POS printing.

Log in to reply