Qt Print Dialog won't open
-
wrote on 30 Jan 2024, 17:12 last edited by
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.
-
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.
@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.
-
@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.
wrote on 30 Jan 2024, 17:24 last edited by@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-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
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).
-
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).
wrote on 30 Jan 2024, 17:49 last edited by@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-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
Your testcase (apart from MainWindow -> QMainWindow) works fine here on windows.
-
@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
-
wrote on 30 Jan 2024, 19:01 last edited by
@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.
-
wrote on 1 Feb 2024, 07:16 last edited by
Maybe try
show()
instead. I am not sure if it does anything different thanopen()
, though. -
@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
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()
andprintDialog->exec()
and both worked fine.With Qt 6.6.0.
1/10