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. Create QPrinter is very slow under Qt5
Forum Updated to NodeBB v4.3 + New Features

Create QPrinter is very slow under Qt5

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprinterqelapsedtimerqt5.5qt4.8.7slow
7 Posts 3 Posters 3.4k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cfdev
    wrote on 19 Nov 2015, 17:07 last edited by cfdev
    #1

    Hi everyone,
    Why under Qt 5.5 the creation of QPrint object is very slow:

    This code
    [code]
    QElapsedTimer timer;
    timer.start();
    QPrinter printer;
    qDebug() << "The operation took" << timer.elapsed() << "milliseconds";
    [/code]

    Measured with QElapsedTimer, Output:
    Qt4.8.7
    The operation took **740 milliseconds **

    Qt5.5
    The operation took 2391 milliseconds

    Amazing?!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on 19 Nov 2015, 18:37 last edited by
      #2

      Hi,

      IMO your code is not correct. This should be the right way to measure the time

      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QElapsedTimer timer;
      
          timer.start();
          QPrinter printer;
          qint64 elapsed = timer.nsecsElapsed();
      
          qDebug() << "Elapsed:" << elapsed << "ns";
      
          return 0;
      }
      

      because in your code elapsed() is called only after some output operations.

      Anyway, in my environment (Qt 5.5.1 on OS X) the output is always between 1.2 and 1.6 ms.
      In which platform are you running that code?

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      C 1 Reply Last reply 19 Nov 2015, 19:24
      0
      • M mcosta
        19 Nov 2015, 18:37

        Hi,

        IMO your code is not correct. This should be the right way to measure the time

        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
        
            QElapsedTimer timer;
        
            timer.start();
            QPrinter printer;
            qint64 elapsed = timer.nsecsElapsed();
        
            qDebug() << "Elapsed:" << elapsed << "ns";
        
            return 0;
        }
        

        because in your code elapsed() is called only after some output operations.

        Anyway, in my environment (Qt 5.5.1 on OS X) the output is always between 1.2 and 1.6 ms.
        In which platform are you running that code?

        C Offline
        C Offline
        cfdev
        wrote on 19 Nov 2015, 19:24 last edited by
        #3

        @mcosta I use the typical case in the doc
        http://doc.qt.io/qt-4.8/qelapsedtimer.html

        My env: MSWindows7 64bit

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on 19 Nov 2015, 19:28 last edited by
          #4

          Hi,

          changing my code according the Qt doc doesn't change the result. IMO that code is not correct if you want to make a real measure

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cfdev
            wrote on 20 Nov 2015, 08:41 last edited by
            #5

            With your code:

            Qt4.8.7
            MSWindows 7 64bit (bin 32bit): The operation took 683 835637 ns

            Qt5.5
            MSWindows 7 64bit (bin 32bit): The operation took 2423 792254 ns
            Ubuntu 14.04.3 LTS 64bits: The operation took 17 481614 ns

            Big difference with Linux system.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on 20 Nov 2015, 08:58 last edited by
              #6

              Hi,

              seems that for some reason on your Windows machine QPrinter is very slow.
              I suggest to open a BUGREPORT; provide as many information as you can

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kmk01
                wrote on 29 Apr 2025, 14:41 last edited by
                #7

                I know it's been a few years, but I was getting this because I had a defunct network printer in Windows. Removing the offending printer from Windows Printers settings fixed the problem for me.

                1 Reply Last reply
                1

                • Login

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