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. Retrieve the file path using Qprinter or Qpainter class.
Forum Updated to NodeBB v4.3 + New Features

Retrieve the file path using Qprinter or Qpainter class.

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

    Hi all,

    I want to create a log file in a path from where the user creates a file for "print to file"(The log file should be created in the same folder, from where the print file is chosen). Currently I am opening the save dialog by calling the QPainter constructor as follows:

        QPainter GraphPainter(&SeqPrint);
    

    where SeqPrint is the object of QPrinter.

    I cannot find any APIs of QPrinter or QPainter which can fetch the file path dynamically according to user's choice from the opened save dialog. Though there are docName() and OutPutFileName() functions provided by QPrinter class, they will not return the file path unless it is set before(My requirement is to choose the file path from the dialog dynamically).

    I could see that the QFileDialog class provides many APIs to fetch the file path dynamically from the open file dialog. Since it is mandatory that the save dialog should be opened by calling the QPainter constructor, I cannot opt for QFileDialog class.

    Please suggest a solution for this.

    Pl45m4P jsulmJ 2 Replies Last reply
    0
    • Q Qt_User444

      Hi all,

      I want to create a log file in a path from where the user creates a file for "print to file"(The log file should be created in the same folder, from where the print file is chosen). Currently I am opening the save dialog by calling the QPainter constructor as follows:

          QPainter GraphPainter(&SeqPrint);
      

      where SeqPrint is the object of QPrinter.

      I cannot find any APIs of QPrinter or QPainter which can fetch the file path dynamically according to user's choice from the opened save dialog. Though there are docName() and OutPutFileName() functions provided by QPrinter class, they will not return the file path unless it is set before(My requirement is to choose the file path from the dialog dynamically).

      I could see that the QFileDialog class provides many APIs to fetch the file path dynamically from the open file dialog. Since it is mandatory that the save dialog should be opened by calling the QPainter constructor, I cannot opt for QFileDialog class.

      Please suggest a solution for this.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Qt_User444

      Just use the filename/path from your save dialog. Of course you have to specify it in your QPrinter's setOutputFileName(QString fn).
      Otherwise how should your pdf printer know where to print?!

      • https://doc.qt.io/qt-5/qprinter.html#setOutputFileName

      @Qt_User444 said in Retrieve the file path using Qprinter or Qpainter class.:

      Since it is mandatory that the save dialog should be opened by calling the QPainter constructor

      This is not possible unless you modify your Qt source code.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • Q Qt_User444

        Hi all,

        I want to create a log file in a path from where the user creates a file for "print to file"(The log file should be created in the same folder, from where the print file is chosen). Currently I am opening the save dialog by calling the QPainter constructor as follows:

            QPainter GraphPainter(&SeqPrint);
        

        where SeqPrint is the object of QPrinter.

        I cannot find any APIs of QPrinter or QPainter which can fetch the file path dynamically according to user's choice from the opened save dialog. Though there are docName() and OutPutFileName() functions provided by QPrinter class, they will not return the file path unless it is set before(My requirement is to choose the file path from the dialog dynamically).

        I could see that the QFileDialog class provides many APIs to fetch the file path dynamically from the open file dialog. Since it is mandatory that the save dialog should be opened by calling the QPainter constructor, I cannot opt for QFileDialog class.

        Please suggest a solution for this.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Qt_User444 said in Retrieve the file path using Qprinter or Qpainter class.:

        Since it is mandatory that the save dialog should be opened by calling the QPainter constructor

        Why should QPainter open any dialogs?! It's job is painting, not showing any dialogs...
        But if, for some strange reason, you really need to do so then subclass QPainter and add your own constructor.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

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