c++ - How to use Qt QPrinter to send cut paper command -
i writing qt desktop programme need print receipt after transaction. need issue "cut paper" in end of each receipt. understand next ascii characters(ascii 27 + ascii 105) need sent @ end of print text cutting paper.
i not find documentation on how send using qprinter. utilize qprinter & qpainter implement printing.
if has tried please advice how handle cutting paper printer command in qt.
i found reply question , posting may useful others.
i used append(ascii character) command append printer commands printer.
here sample code used:
qstring printer_name = "printerone"; qdebug() << "test printing started..."; qbytearray print_content_ba("test print text "); print_content_ba.append("\n"); //add end of receipt buffer & cutting command print_content_ba.append(27); print_content_ba.append(105); handle p_hprinter; doc_info_1 docinfo; dword dwjob = 0l; dword dwbyteswritten = 0l; bool bstatus = false; //code convert qstring wchar_t wchar_t szprintername[255]; int length = printer_name.towchararray(szprintername); szprintername[length]=0; if (openprinter(szprintername,&p_hprinter,null)){ qdebug() << "printer opening success " << qstring::fromwchararray(szprintername); docinfo.pdocname = l"loyalty receipt"; docinfo.poutputfile = null; docinfo.pdatatype = l"raw"; dwjob = startdocprinter( p_hprinter, 1, (lpbyte)&docinfo ); if (dwjob > 0) { qdebug() << "job set."; bstatus = startpageprinter(p_hprinter); if (bstatus) { qdebug() << "writing text printer" << print_content_ba ; bstatus = writeprinter(p_hprinter,print_content_ba.data(),print_content_ba.length(),&dwbyteswritten); if(bstatus > 0){ qdebug() << "printer write success" << bstatus; } endpageprinter(p_hprinter); } else { qdebug() << "could not start printer"; } enddocprinter(p_hprinter); qdebug() << "closing doc"; } else { qdebug() << "couldn't create job"; } closeprinter(p_hprinter); qdebug() << "closing printer"; } else{ qdebug() << "printer opening failed"; }
c++ qt printing qprinter
No comments:
Post a Comment