Create QPrinter is very slow under Qt5

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

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

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

    The operation took 2391 milliseconds


  • 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;
        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?

  • @mcosta I use the typical case in the doc

    My env: MSWindows7 64bit

  • 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

  • With your code:

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

    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.

  • 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