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. how open print dialog to select printer.
Forum Updated to NodeBB v4.3 + New Features

how open print dialog to select printer.

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 5.9k Views 2 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.
  • G Offline
    G Offline
    Gaurav Badgujar
    wrote on 23 Jun 2017, 13:12 last edited by
    #1

    Hi,

    i want to print a page from qwebview. and want to open print dialog and select printer from it then print that page.

    give some solution.

    Regards,
    Gaurav Badgujar.

    R 1 Reply Last reply 23 Jun 2017, 13:24
    0
    • G Gaurav Badgujar
      23 Jun 2017, 13:12

      Hi,

      i want to print a page from qwebview. and want to open print dialog and select printer from it then print that page.

      give some solution.

      Regards,
      Gaurav Badgujar.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 Jun 2017, 13:24 last edited by
      #2

      @Gaurav-Badgujar

      QPrinter* printer = ...;
      QPrintDialog printDialog(printer, parent);
      if (printDialog.exec() == QDialog::Accepted) {
          // print ...
          webview->print( printer );
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Gaurav Badgujar
        wrote on 3 Jul 2017, 06:11 last edited by
        #3

        i use given snippet but Printer Dialog not opened.
        Give some solution to print a page from qwebview.
        we want to open print dialog same as .pdf viewer's print dialog.

        R 1 Reply Last reply 3 Jul 2017, 06:15
        0
        • G Gaurav Badgujar
          3 Jul 2017, 06:11

          i use given snippet but Printer Dialog not opened.
          Give some solution to print a page from qwebview.
          we want to open print dialog same as .pdf viewer's print dialog.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 3 Jul 2017, 06:15 last edited by
          #4

          @Gaurav-Badgujar said in how open print dialog to select printer.:

          i use given snippet but Printer Dialog not opened.

          show your code pls.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gaurav Badgujar
            wrote on 3 Jul 2017, 06:44 last edited by
            #5

            void ClassName::PrintButtonClick()
            {
            QPrinter* printer;
            QPrintDialog printDialog(&printer, parent);
            if (printDialog.exec() == QDialog::Accepted) {
            this->webview->print( &printer );
            }

            i use above snippet but PrintDialog not invoked.

            J R 2 Replies Last reply 3 Jul 2017, 06:50
            0
            • G Gaurav Badgujar
              3 Jul 2017, 06:44

              void ClassName::PrintButtonClick()
              {
              QPrinter* printer;
              QPrintDialog printDialog(&printer, parent);
              if (printDialog.exec() == QDialog::Accepted) {
              this->webview->print( &printer );
              }

              i use above snippet but PrintDialog not invoked.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 3 Jul 2017, 06:50 last edited by jsulm 7 Mar 2017, 06:57
              #6

              @Gaurav-Badgujar Did you make sure PrintButtonClick() was called?

              Also this is wrong (actually you're passing a pointer to a pointer which does not point to valid QPrinter instance):

              QPrinter* printer;
              QPrintDialog printDialog(&printer, parent);
              

              You need to have a QPrinter instance:

              QPrinter printer;
              QPrintDialog printDialog(&printer, parent);
              

              else you're passing a dangling pointer to QPrintDialog.

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

              1 Reply Last reply
              0
              • G Gaurav Badgujar
                3 Jul 2017, 06:44

                void ClassName::PrintButtonClick()
                {
                QPrinter* printer;
                QPrintDialog printDialog(&printer, parent);
                if (printDialog.exec() == QDialog::Accepted) {
                this->webview->print( &printer );
                }

                i use above snippet but PrintDialog not invoked.

                R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 3 Jul 2017, 07:02 last edited by
                #7

                @Gaurav-Badgujar
                i doubt that this even compiles?!
                Do as @jsulm showed.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gaurav Badgujar
                  wrote on 3 Jul 2017, 07:07 last edited by
                  #8

                  sorry its my mistake in snippet.
                  i write ,
                  void ClassName::PrintButtonClick()
                  {
                  QPrinter printer;
                  QPrintDialog printDialog(&printer, parent);
                  if (printDialog.exec() == QDialog::Accepted) {
                  this->webview->print( &printer );
                  }
                  but QPrintDialog not invoked.

                  J 1 Reply Last reply 3 Jul 2017, 07:49
                  0
                  • G Gaurav Badgujar
                    3 Jul 2017, 07:07

                    sorry its my mistake in snippet.
                    i write ,
                    void ClassName::PrintButtonClick()
                    {
                    QPrinter printer;
                    QPrintDialog printDialog(&printer, parent);
                    if (printDialog.exec() == QDialog::Accepted) {
                    this->webview->print( &printer );
                    }
                    but QPrintDialog not invoked.

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 3 Jul 2017, 07:49 last edited by
                    #9

                    @Gaurav-Badgujar Did you make sure PrintButtonClick() was called?

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

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      Gaurav Badgujar
                      wrote on 3 Jul 2017, 09:20 last edited by
                      #10

                      yes..PrintButtonClick() function call.

                      mrjjM 1 Reply Last reply 3 Jul 2017, 15:16
                      0
                      • G Gaurav Badgujar
                        3 Jul 2017, 09:20

                        yes..PrintButtonClick() function call.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 3 Jul 2017, 15:16 last edited by mrjj 7 Mar 2017, 15:17
                        #11

                        @Gaurav-Badgujar
                        Are you showing the real code ?
                        It works here. Same code shows Dialog
                        Only change is parent is replaced with this

                        alt text

                        void MainWindow::on_pushButton_2_released()
                        {
                        QPrinter printer;
                        QPrintDialog printDialog(&printer, this);<<<< said parent which didnt compile
                        if (printDialog.exec() == QDialog::Accepted) {
                        PrintWidget(this);
                        }
                        }

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          Gaurav Badgujar
                          wrote on 7 Jul 2017, 14:19 last edited by
                          #12

                          hi,
                          i used below code.

                          void ClassName::PrintButtonClick()
                          {
                          QPrinter printer;
                          QPrintDialog printDialog(&printer, parent);![0_1499437164064_Crashed.png](Uploading 100%)
                          if (printDialog.exec() == QDialog::Accepted)
                          {
                          this->webview->print( &printer ); // application crashed when this line is executed.![alt text](image url)
                          }
                          }

                          with this print dialog executed but when webview's print function executed at that time application crashed.
                          give some suggestion to resolve this issue.

                          0_1499437179572_Crashed.png

                          mrjjM 1 Reply Last reply 7 Jul 2017, 18:01
                          0
                          • G Gaurav Badgujar
                            7 Jul 2017, 14:19

                            hi,
                            i used below code.

                            void ClassName::PrintButtonClick()
                            {
                            QPrinter printer;
                            QPrintDialog printDialog(&printer, parent);![0_1499437164064_Crashed.png](Uploading 100%)
                            if (printDialog.exec() == QDialog::Accepted)
                            {
                            this->webview->print( &printer ); // application crashed when this line is executed.![alt text](image url)
                            }
                            }

                            with this print dialog executed but when webview's print function executed at that time application crashed.
                            give some suggestion to resolve this issue.

                            0_1499437179572_Crashed.png

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 7 Jul 2017, 18:01 last edited by mrjj 7 Jul 2017, 18:02
                            #13

                            @Gaurav-Badgujar
                            Are you sure this->webview is valid ?
                            Only reason i can think off.
                            It shows zero.
                            Often sign of dangling pointer

                            Please show the function where you new it.

                            1 Reply Last reply
                            1

                            • Login

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