Unsolved 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, [=]() { //watcher.waitForFinished(); finished(); }); watcher.setFuture( QtConcurrent::run([=]() { QPrinter pdfWriter; pdfWriter.setPageSize(QPagedPaintDevice::A4); //It does not work. Trick, I will use the painter pdfWriter.setPageMargins(10, 10, 10, 10, QPrinter::Millimeter); double margin_ForPainter = 20; pdfWriter.setOrientation(QPrinter::Portrait); pdfWriter.setFullPage(true); pdfWriter.setOutputFileName("pdf_generated.pdf"); QTextDocument document; QString html = "<head>" "< / head>"; pdfWriter.setOutputFormat(QPrinter::PdfFormat); document.setHtml(html); //Open the file generated QDesktopServices::openUrl(QUrl::fromLocalFile("pdf_generated.pdf")); }));
-
@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?
-
@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
-
Hi,
Can you provide a complete minimal example that shows that behaviour ?