Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4250920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:35:32+00:00 2026-05-21T04:35:32+00:00

I need to output a ZPL script to a Zebra printer in a Qt

  • 0

I need to output a ZPL script to a Zebra printer in a Qt application.
The printer is on a smb share network configured as raw printer in the client computer.

Everything goes fine if I call cupsPrintFile( "printer_name", "./tmp_print_file.zpl", "", 0, NULL ) from a C++ test program.

If I use QTextDocument::print() using the same text in “./tmp_print_file.zpl” as document, nothing gets printed.
I sniffed the network and found that the data being sent to the printer server is not raw data, but, a postscript!

Is there any way to get the data sent to the printer with no modification at all?

  • Let me be clear that I don’t want to render a text, but just send the label script, that is ready to print, directly to the printer, that understands the ZPL protocol.

Thanks for all.


EDIT:

As @Martin said, I tried:

printer.setOutputFormat( QPrinter::NativeFormat );
QTextDocument   *doc = new QTextDocument( QString( label ), this );
doc->print( &printer );

but it didn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:35:32+00:00Added an answer on May 21, 2026 at 4:35 am

    Before I start, must thank Dave. His suggestion to bypass the temporary file while printing with CUPs works fine.

    Now, my conclusion: There is no easy way to print raw data using Qt only.
    Maybe creating custom QPainter or going down to the bits of QPrinter could give a solution, but it would take me too much time.

    The final solution is simply use CUPs API inside my Qt application. Unfortunatelly, it is not portable.

    Here is a snippet:

    #include    <cups/cups.h>
    
    //...
    
    int print_label( const char *text, const char *printer_name, const char *job_name )
    {
        int jobId = 0;
    
        jobId = cupsCreateJob( CUPS_HTTP_DEFAULT, printer_name, job_name, 0, NULL );
    
        if ( jobId > 0 )
        {
            qDebug( ) << "Printing job #" << jobId << " (\"" << job_name << "\").";
    
            const char* format = CUPS_FORMAT_TEXT;  // CUPS_FORMAT_POSTSCRIPT;
    
            cupsStartDocument( CUPS_HTTP_DEFAULT, printer_name, jobId, text, format, true );
            cupsWriteRequestData( CUPS_HTTP_DEFAULT, text, strlen( text ) );
    
            cupsFinishDocument( CUPS_HTTP_DEFAULT, printer_name );
        }
    
        return jobId;
    }
    
    //...
    
    // Now, inside any Qt function (may be a slot):
    
    QPrinter printer;
    
    QPrintDialog *dialog = new QPrintDialog( &printer, this );
    dialog->setWindowTitle( tr( "Zebra label" ) );
    if ( dialog->exec( ) != QDialog::Accepted )
        return;
    
        // This is the sample label. Can be anything.
    const char  label[] =
        "^XA~TA000~JSN^LT0^MNW^MTD^PON^PMN^LH0,0^JMA^PR4,4^MD0^JUS^LRN^CI0^XZ\n"
        "^XA\n"
        "^MMT\n"
        "^LL0600\n"
        "^PW900\n"
        "^LS0\n"
        "^BY2,3,54^FT24,109^BCN,,Y,N\n"
        "^FD>;43210000>773>0000^FS\n"
        "^PQ1,0,1,Y^XZ\n";
    
        // Informative only.
    ui->txtLabelScript->setPlainText( label );
    
        // Call the printing function.
    if ( print_label( label, printer.printerName( ).toAscii( ), "Zebra_Label" ) == 0 )
        qDebug( ) << "CUPS Error: " << ippErrorString( cupsLastError( ) );
    

    And it’s done.

    Don’t forget to link libcups (-lcups).

    I still hope any buddy to add another solution prooving that Qt-only is possible. Meanwhile, it is enough.

    Thanks everybody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to output some JavaScript in a WebControl based on some processing and
I need to output the contents of a text field using MS Query Analyzer.
Let's say we have 0.33 , we need to output 1/3 . If we
I have a list of objects which need to be output 2 items per
I'm looking for the equivalent of a urlencode for terminal output -- I need
I need to pad the output of an integer to a given length. For
I need to be able to launch a process and read the output into
I need to run a Linux CLI command and get its stdout output from
I need to run a native program and retrieve the output in an Adobe
I need some way to add a class attribute to the output of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.