Important: Please read the Qt Code of Conduct -

[SOLVED] QPrintPreviewDialog: problem with updating preview

  • I added the printer selector (QComboBox-based) into standard QPrintPreviewDialog to allow user to select required printer. As soon as selection is changed, dialog updates preview of pages by QPrintPreviewWidget::updatePreview() method:

    @ QList<QPrintPreviewWidget*> list = dialog->findChildren<QPrintPreviewWidget*>();
    if (list.isEmpty())

    QPrintPreviewWidget *preview = list.first();

    But I'm faced by the following problem here. The updatePreview() method crashes the application.

    I found out, that in my slot, connected to QPrintPreviewDialog::paintRequested() signal, there are 2 constructions, which causes the problem.

    The first of them uses QEventLoop::exec() method. You can find more details here

    The second one uses QProgressDialog::setValue(int) method.

    If I disable both of them the problem disappears. It's really strange, because when QPrintPreviewDialog is shown at the first time, the mentioned slot works properly, but when updatePreview method is called in already shown dialog, the problem occurs.

    Any ideas?

    Thanks in advance.

    P.S. Qt v4.7.4, Windows 7

  • Test it on an another version.

  • As a workaround solution I replaced this line:


    with these ones:


    I.e. I hide QPrintPreviewWidget to block its event loop.

Log in to reply