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 505 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 30 Jan 2024, 17:12 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.

    C 1 Reply Last reply 30 Jan 2024, 17:16
    0
    • C cadol001
      30 Jan 2024, 17:12
      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.

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 30 Jan 2024, 17:16 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 30 Jan 2024, 17:24
      0
      • C Christian Ehrlicher
        30 Jan 2024, 17:16

        @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 30 Jan 2024, 17:24 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

        C 1 Reply Last reply 30 Jan 2024, 17:40
        0
        • C cadol001
          30 Jan 2024, 17:24

          @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

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 30 Jan 2024, 17:40 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 30 Jan 2024, 17:49
          0
          • C Christian Ehrlicher
            30 Jan 2024, 17:40

            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 30 Jan 2024, 17:49 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

            C M S 3 Replies Last reply 30 Jan 2024, 18:30
            0
            • C cadol001
              30 Jan 2024, 17:49

              @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

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 30 Jan 2024, 18:30 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
                30 Jan 2024, 17:49

                @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 30 Jan 2024, 18:52 last edited by
                #7

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

                C 1 Reply Last reply 30 Jan 2024, 19:01
                0
                • M mpergand
                  30 Jan 2024, 18:52

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

                  C Offline
                  C Offline
                  cadol001
                  wrote on 30 Jan 2024, 19:01 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 1 Feb 2024, 07:16 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
                      30 Jan 2024, 17:49

                      @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

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 1 Feb 2024, 20:59 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

                      1/10

                      30 Jan 2024, 17:12

                      • Login

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