Important: Please read the Qt Code of Conduct -

Qprinter inside a thread does not create a file in mac

  • Hello, I have a doubt. In windows, it works well, But in mac, It doesn´t. What I want to do is to create a pdf report and first I run it in the main thread. Then I wanted to add a loader so I run it in another thread. And then the problem started in mac. And it does not generate any output in the qprinter. If I remove the loader it works again. The problem is the thread (QConcurrent::run) but I do not understand why. And why only in mac. Thank you

    static QFutureWatcher<void> watcher;
    QObject::connect(&watcher, &QFutureWatcherBase::finished, [=]() {
    	QtConcurrent::run([=]() { 
    QPrinter pdfWriter;
    //It does not work. Trick, I will use the painter
    pdfWriter.setPageMargins(10, 10, 10, 10, QPrinter::Millimeter);
    double margin_ForPainter = 20;
    QTextDocument document;
    QString html =
                   "< / head>";
    //Open the file generated

  • Moderators

    @zandarina hi, define a proper path, on MacOS you don't have write permission where pdfWriter.setOutputFileName("pdf_generated.pdf"); is trying to create the file

  • Hi the resource dir or bundle is created. at the beginning in mac. This setouputFileName if I do not launch any thread it creates the file in the correct place. I do not understand why I do not have persimission if a thread is created with the watcher. The bundle is lost?

  • Moderators

    @zandarina ok, I miss read than, I thought it wouldn't work at all, usually one isn't allowed to create files inside the package contents folder

  • Lifetime Qt Champion


    Can you provide a complete minimal example that shows that behaviour ?

Log in to reply