Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

[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())
    return;

    QPrintPreviewWidget *preview = list.first();
    preview->updatePreview();@
    

    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 http://qt-project.org/forums/viewthread/35615/

    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:

    @preview->updatePreview();@

    with these ones:

    @preview->hide();
    preview->updatePreview();
    preview->show();@

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


Log in to reply