Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved how open print dialog to select printer.

    General and Desktop
    4
    13
    4989
    Loading More Posts
    • 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
      Gaurav Badgujar last edited by

      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.

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Gaurav Badgujar last edited by

        @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 Reply Quote 1
        • G
          Gaurav Badgujar last edited by

          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.

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @Gaurav Badgujar last edited by

            @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 Reply Quote 0
            • G
              Gaurav Badgujar last edited by

              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.

              jsulm raven-worx 2 Replies Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @Gaurav Badgujar last edited by jsulm

                @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 Reply Quote 0
                • raven-worx
                  raven-worx Moderators @Gaurav Badgujar last edited by

                  @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 Reply Quote 0
                  • G
                    Gaurav Badgujar last edited by

                    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.

                    jsulm 1 Reply Last reply Reply Quote 0
                    • jsulm
                      jsulm Lifetime Qt Champion @Gaurav Badgujar last edited by

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

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

                      1 Reply Last reply Reply Quote 0
                      • G
                        Gaurav Badgujar last edited by

                        yes..PrintButtonClick() function call.

                        mrjj 1 Reply Last reply Reply Quote 0
                        • mrjj
                          mrjj Lifetime Qt Champion @Gaurav Badgujar last edited by mrjj

                          @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 Reply Quote 0
                          • G
                            Gaurav Badgujar last edited by

                            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

                            mrjj 1 Reply Last reply Reply Quote 0
                            • mrjj
                              mrjj Lifetime Qt Champion @Gaurav Badgujar last edited by mrjj

                              @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 Reply Quote 1
                              • First post
                                Last post