Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
how open print dialog to select printer.
-
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.
-
QPrinter* printer = ...; QPrintDialog printDialog(printer, parent); if (printDialog.exec() == QDialog::Accepted) { // print ... webview->print( printer ); }
-
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.
-
@Gaurav-Badgujar said in how open print dialog to select printer.:
i use given snippet but Printer Dialog not opened.
show your code pls.
-
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.
-
@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.
-
@Gaurav-Badgujar
i doubt that this even compiles?!
Do as @jsulm showed.
-
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.
-
@Gaurav-Badgujar Did you make sure PrintButtonClick() was called?
-
yes..PrintButtonClick() function call.
-
@Gaurav-Badgujar
Are you showing the real code ?
It works here. Same code shows Dialog
Only change is parent is replaced with thisvoid MainWindow::on_pushButton_2_released()
{
QPrinter printer;
QPrintDialog printDialog(&printer, this);<<<< said parent which didnt compile
if (printDialog.exec() == QDialog::Accepted) {
PrintWidget(this);
}
}
-
hi,
i used below code.void ClassName::PrintButtonClick()
{
QPrinter printer;
QPrintDialog printDialog(&printer, parent);
if (printDialog.exec() == QDialog::Accepted)
{
this->webview->print( &printer ); // application crashed when this line is executed.
}
}with this print dialog executed but when webview's print function executed at that time application crashed.
give some suggestion to resolve this issue.
-
@Gaurav-Badgujar
Are you sure this->webview is valid ?
Only reason i can think off.
It shows zero.
Often sign of dangling pointerPlease show the function where you new it.