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. Qt Print Dialog won't open
Forum Updated to NodeBB v4.3 + New Features

Qt Print Dialog won't open

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 506 Views 3 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.
  • C Offline
    C Offline
    cadol001
    wrote on last edited by
    #1
    QPrinter printer;
    QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
    printDialog->setAttribute( Qt::WA_DeleteOnClose );
    printDialog->setModal(true);
    printDialog->open();
    

    This won't work, but if I call exec() it shows. What do I do? I can't use exec since it will block things.

    Christian EhrlicherC 1 Reply Last reply
    0
    • C cadol001
      QPrinter printer;
      QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
      printDialog->setAttribute( Qt::WA_DeleteOnClose );
      printDialog->setModal(true);
      printDialog->open();
      

      This won't work, but if I call exec() it shows. What do I do? I can't use exec since it will block things.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @cadol001 said in Qt Print Dialog won't open:

      I can't use exec since it will block things.

      What should be blocked? The user must do some settings, then you can continue.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @cadol001 said in Qt Print Dialog won't open:

        I can't use exec since it will block things.

        What should be blocked? The user must do some settings, then you can continue.

        C Offline
        C Offline
        cadol001
        wrote on last edited by
        #3

        @Christian-Ehrlicher I don't know what you mean, but I would like to get it to work with open(). The docs for 5.15 has an override method for open() yet, even with a minimal example such as this one, the print dialog doesn't open

        exec() blocks everything. nothing should be blocked

        Christian EhrlicherC 1 Reply Last reply
        0
        • C cadol001

          @Christian-Ehrlicher I don't know what you mean, but I would like to get it to work with open(). The docs for 5.15 has an override method for open() yet, even with a minimal example such as this one, the print dialog doesn't open

          exec() blocks everything. nothing should be blocked

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then show some more code. Don't know why exec() will not work here though. It does not block anything (execept the program control flow).

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          C 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Then show some more code. Don't know why exec() will not work here though. It does not block anything (execept the program control flow).

            C Offline
            C Offline
            cadol001
            wrote on last edited by
            #5

            @Christian-Ehrlicher that is exactly why I cannot use exec()

            #include "mainwindow.h"
            
            #include <QApplication>
            #include <QPrinter>
            #include <QPrintDialog>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                MainWindow w;
                w.show();
            
                QPrinter printer;
                QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
                printDialog->setAttribute( Qt::WA_DeleteOnClose );
                printDialog->open();
                return a.exec();
            }
            

            All I did was put this snippet in the default widgets project. Switching out open() with exec() just magically works. I just can't use exec. Thanks

            Christian EhrlicherC M SGaistS 3 Replies Last reply
            0
            • C cadol001

              @Christian-Ehrlicher that is exactly why I cannot use exec()

              #include "mainwindow.h"
              
              #include <QApplication>
              #include <QPrinter>
              #include <QPrintDialog>
              
              int main(int argc, char *argv[])
              {
                  QApplication a(argc, argv);
                  MainWindow w;
                  w.show();
              
                  QPrinter printer;
                  QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
                  printDialog->setAttribute( Qt::WA_DeleteOnClose );
                  printDialog->open();
                  return a.exec();
              }
              

              All I did was put this snippet in the default widgets project. Switching out open() with exec() just magically works. I just can't use exec. Thanks

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Your testcase (apart from MainWindow -> QMainWindow) works fine here on windows.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • C cadol001

                @Christian-Ehrlicher that is exactly why I cannot use exec()

                #include "mainwindow.h"
                
                #include <QApplication>
                #include <QPrinter>
                #include <QPrintDialog>
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    MainWindow w;
                    w.show();
                
                    QPrinter printer;
                    QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
                    printDialog->setAttribute( Qt::WA_DeleteOnClose );
                    printDialog->open();
                    return a.exec();
                }
                

                All I did was put this snippet in the default widgets project. Switching out open() with exec() just magically works. I just can't use exec. Thanks

                M Offline
                M Offline
                mpergand
                wrote on last edited by
                #7

                @cadol001
                Doesn't work for me as well on Mac 10.15 Qt5.15.

                C 1 Reply Last reply
                0
                • M mpergand

                  @cadol001
                  Doesn't work for me as well on Mac 10.15 Qt5.15.

                  C Offline
                  C Offline
                  cadol001
                  wrote on last edited by
                  #8

                  @mpergand @Christian-Ehrlicher thank you, I guess it is a Mac issue. I just tried on Qt 6.5 on Mac, and it also does not work.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #9

                    Maybe try show() instead. I am not sure if it does anything different than open(), though.

                    1 Reply Last reply
                    0
                    • C cadol001

                      @Christian-Ehrlicher that is exactly why I cannot use exec()

                      #include "mainwindow.h"
                      
                      #include <QApplication>
                      #include <QPrinter>
                      #include <QPrintDialog>
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication a(argc, argv);
                          MainWindow w;
                          w.show();
                      
                          QPrinter printer;
                          QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
                          printDialog->setAttribute( Qt::WA_DeleteOnClose );
                          printDialog->open();
                          return a.exec();
                      }
                      

                      All I did was put this snippet in the default widgets project. Switching out open() with exec() just magically works. I just can't use exec. Thanks

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      @cadol001 said in Qt Print Dialog won't open:

                      @Christian-Ehrlicher that is exactly why I cannot use exec()

                      #include "mainwindow.h"
                      
                      #include <QApplication>
                      #include <QPrinter>
                      #include <QPrintDialog>
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication a(argc, argv);
                          MainWindow w;
                          w.show();
                      
                          QPrinter printer;
                          QPrintDialog* printDialog = new QPrintDialog(&printer, 0);
                          printDialog->setAttribute( Qt::WA_DeleteOnClose );
                          printDialog->open();
                          return a.exec();
                      }
                      

                      All I did was put this snippet in the default widgets project. Switching out open() with exec() just magically works. I just can't use exec. Thanks

                      I replaced MainWindow by QMainWindow and tested both printDialog->open() and printDialog->exec() and both worked fine.

                      With Qt 6.6.0.

                      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
                      1

                      • Login

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