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 Gaurav Badgujar

    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-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on 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 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.

      raven-worxR 1 Reply Last reply
      0
      • G Gaurav Badgujar

        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-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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 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.

          jsulmJ raven-worxR 2 Replies Last reply
          0
          • G Gaurav Badgujar

            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.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #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

              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.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on 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 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.

                jsulmJ 1 Reply Last reply
                0
                • G Gaurav Badgujar

                  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.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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 last edited by
                    #10

                    yes..PrintButtonClick() function call.

                    mrjjM 1 Reply Last reply
                    0
                    • G Gaurav Badgujar

                      yes..PrintButtonClick() function call.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #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 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
                        0
                        • G Gaurav Badgujar

                          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 last edited by mrjj
                          #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