Qt Print Dialog won't open
-
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.
@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).
@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
-
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.