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. Qprinter inside a thread does not create a file in mac
Forum Updated to NodeBB v4.3 + New Features

Qprinter inside a thread does not create a file in mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 354 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.
  • Z Offline
    Z Offline
    zandarina
    wrote on last edited by
    #1

    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"));
    }));
    
    J.HilkJ 1 Reply Last reply
    0
    • Z zandarina

      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"));
      }));
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zandarina
        wrote on last edited by
        #3

        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?

        J.HilkJ 1 Reply Last reply
        0
        • Z zandarina

          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?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

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