QPrinter: Must construct a QCoreApplication before a QPrinter



  • On Windows with Qt version 5.6, the following line causes my program to stop :

    QPrinter * printer = new QPrinter(QPrinter::HighResolution);
    

    With the following message in the debugger's Output window :

    QPrinter: Must construct a QCoreApplication before a QPrinter
    

    Since at the time this happens my application is already long past initialization and the event loop has already treated thousands of events and is certainly not missing, I find this message quite puzzling.


  • Qt Champions 2016

    Hi
    Can you reproduce this in small sample?
    Could just be a 5.6 bug :)



  • @mrjj

    Unfortunately, it cannot be reproduced in a simple project.
    My guess would be some conflict with some system library that I'm linking to.

    For some reason I cannot debug into this line without going into disassembly mode, which is too hopeless.
    Any advice for debugging it?


  • Qt Champions 2016

    HI
    But do you do anything kinky with the QApplication ?
    or does the system library contains event loops also.
    Else I dont see why it should complain.

    I guess I would look in source to see if I can
    get more information about when it gives this error.

    also go look in bugs system
    https://bugreports.qt.io/browse/QTBUG-43877?jql=text ~ "QPrinter"



  • @mrjj

    Found it - yes, I did a kinky thing.

    If anyone ever stumbles upon this one - it comes from linking a debug build with Qt5PrintSupport.lib. A debug build needs to link with Qt5PrintSupportd.lib, or strange things will happen.


  • Qt Champions 2016

    @Harry123
    Nice found!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.