Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextDocument::print ignores # of copies from QPrintDialog

QTextDocument::print ignores # of copies from QPrintDialog

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vikinglief
    wrote on last edited by
    #1

    So I have a simple print method that will print HTML content stored in a QTextDocument. It works reasonably well, but when I print it, it ignores the number of copies set by the QPrintDialog

    I have the following code:

    @
    QPrinter printer;
    QPrintDialog printDialog = QPrintDialog(&printer, this);
    QAbstractPrintDialog::PrintDialogOptions flags = QAbstractPrintDialog::None;
    printDialog.setOptions(flags);

    if (printDialog.exec() == QDialog::Accepted &&
    printer.isValid()) {
    QTextDocument doc;
    doc.setHtml(mHtml);

    doc.print(&printer);
    

    }
    @

    where mHtml is a QString that contains the HTML content.

    Now, on the QPrintDialog that pops up, I set the number of copies to 2, but when I click "Print", it only prints 1 copy.

    I could find nothing in the documentation for QPrinter, QPrintDialog, QTextDocument, or the article "Printing With Qt ":http://doc.qt.nokia.com/4.7/printing.html mention anything about having to manually handle multiple copies.

    So, has anyone bumped into this before? Do I need to manually handle multiple copies? If so, any suggestions on how to handle the collate option?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vikinglief
      wrote on last edited by
      #2

      Someone help me out here, please.

      I've dug through the source code for QTextDocument::print(), and the behavior I was expecting seems to only happen if the printer's "supportsMultipleCopies":http://doc.qt.nokia.com/4.7/qprinter.html#supportsMultipleCopies function returns false.

      (taken from qtextdocument.cpp, lines 1790 - 1796)
      @
      if (printer->collateCopies() == true){
      docCopies = 1;
      pageCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
      } else {
      docCopies = printer->supportsMultipleCopies() ? 1 : printer->copyCount();
      pageCopies = 1;
      }
      @

      Does this mean that it is normally expected for my application to manually handle the printing of multiple copies?

      Can anyone confirm this, please?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris H
        wrote on last edited by
        #3

        Well, according to the "documentation":http://doc.qt.nokia.com/4.7-snapshot/qprinter.html#supportsMultipleCopies "On most systems this function will return true. However, on X11 systems that do not support CUPS, this function will return false. That means the application has to handle the number of copies by printing the same document the required number of times." (emphasis mine)

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vikinglief
          wrote on last edited by
          #4

          But the phrasing on that seems to imply that for the case of it returning true, then the application does not need to handle that case.

          Or am I misreading this?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris H
            wrote on last edited by
            #5

            Actually, what I believe the above code is doing is handling this case for you (that is, when QPrinter won't handle multiple copies, QTextDocument will do it for you). So it would appear that the problem is something like your printer says it supports multiple copies, but when it's told to print them it's not doing so.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vikinglief
              wrote on last edited by
              #6

              However, from other applications (such as word, adobe reader, notepad, etc.), I am able to have it print multiple copies just fine, so I am confused & frustrated as to where the disconnect lies.

              Any thoughts?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris H
                wrote on last edited by
                #7

                Have you compiled Qt with debugging symbols enabled? You could step in and make sure the number of copies is getting set all the way through.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vikinglief
                  wrote on last edited by
                  #8

                  I'm already able to, in VS 2010, "step into" qtextdocument::print(), and walk through there. Is that sufficient? If not, how would I go about ensuring that the debugging symbols are enabled? (I already have the configure -debug-and-release flag set)

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Chris H
                    wrote on last edited by
                    #9

                    If you can step into Qt's functions and see the code, you're good to go. I'd start by putting a breakpoint in QWin32PrintEngine::setProperty() (the file is qprintengine_win.cpp) where it's setting the number of copies property.

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vikinglief
                      wrote on last edited by
                      #10

                      I was able to confirm that it was setting the number of copies to 2 correctly, and that the property was not being changed, so I'm still no closer to solving this issue, but I thank you for your time spent helping me on this.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Chris H
                        wrote on last edited by
                        #11

                        Well, I wouldn't say "no" closer: you know where the problem isn't now, that's a start. I'd start putting in some more breakpoints in between the call to print() and the call to setProperty(), in places where you expect the code to go, and try to figure out at what point it's deciding not to pass the copy count onto the printer driver.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved