Print Preview features fails on Windows 10



  • I have developed a Qt Application on Windows 7 32-bit system. This application is having a print preview feature for which I am using QPrintPreviewWidget.

    I have place all the relevant dlls in a folder along with the release version of the Qt Application.

    This application works fine on Windows 7 32 bit and 64 bit.

    But When I run this application on Windows 10 64 bit, print preview feature does not work. Application crashes.

    All the other functionality are working fine on Windows 10, except print preview.

    I don't know what the problem is??

    Anyone's help for solving it will be appreciated.


  • Qt Champions 2016

    @NIXIN
    Hi
    I think you also need a folder with right name (printsupport)
    http://stackoverflow.com/questions/17175398/deployed-qt5-application-doesnt-print-or-show-print-dialog

    Alternatively, have a look at the exe and plugins with http://www.dependencywalker.com/
    and see if they are missing any DLLS.



  • I build my code on Windows 10 in release mode (Qt v5.6.0).

    And I got this error:

    QWin32PrintEngine::initialize: CreateDC failed (The specified procedure could not be found.)

    I don't know why this error occurs on windows 10 but not on Windows 7.


  • Qt Champions 2016

    @NIXIN
    Hi
    It is impossible to guess at with no code or any other information.
    I would check with other win 10 to see if its reproducible.

    If yes I would go and look in Qt bug system
    https://bugreports.qt.io

    Also, just for sanity. You did try to print from some other non Qt app to test Windows 100% happy ?



  • @NIXIN

    I use the print preview widget on Windows 10 with 5.6.0 with no problems.
    Why not try to build the fontsampler example to see if that works OK.. It has a print preview dialog.



  • @mrjj
    Hi,
    I have developed a sample application which gives the same problem

    widget.h

    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>
    #include <Qpainter>

    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    private slots:
    void on_pushButton_clicked();

    private:
    Ui::Widget *ui;
    };

    #endif // WIDGET_H

    widget.cpp

    #include "widget.h"
    #include "ui_widget.h"
    #include "testdialog.h"

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::on_pushButton_clicked()
    {
    TestDialog dlg;
    dlg.printPreview();
    dlg.exec();
    }

    testdialog.h

    #ifndef TESTDIALOG_H
    #define TESTDIALOG_H

    #include <QDialog>
    #include <QPainter>
    #include <QPrintPreviewWidget>
    #include <QPrinter>
    #include <QDebug>

    namespace Ui {
    class TestDialog;
    }

    class TestDialog : public QDialog
    {
    Q_OBJECT

    public:
    explicit TestDialog(QWidget *parent = 0);
    ~TestDialog();

    void printPreview();
    

    public slots:
    void slot_print(QPrinter *printer);

    private:
    Ui::TestDialog ui;
    QPrintPreviewWidget
    printPreviewWidget;
    QPrinter printer;
    };

    #endif // TESTDIALOG_H

    testdialog.cpp

    #include "testdialog.h"
    #include "ui_testdialog.h"

    TestDialog::TestDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TestDialog)
    {
    ui->setupUi(this);

    setWindowFlags(Qt::Window);
    //printPreviewWidget = NULL;
    

    }

    TestDialog::~TestDialog()
    {
    delete ui;
    }

    void TestDialog::printPreview()
    {
    printPreviewWidget = new QPrintPreviewWidget(&printer, this);

    connect(printPreviewWidget, SIGNAL(paintRequested(QPrinter*)), this, SLOT(slot_print(QPrinter*)));
    
    ui->gridLayout->addWidget(printPreviewWidget);
    

    }

    void TestDialog::slot_print(QPrinter *printer)
    {
    QPainter painterForPrint(printer);

    int viewPortWidth = painterForPrint.viewport().width();
    int viewPortHeight = painterForPrint.viewport().height();

    qDebug() << "View Port Width: " << viewPortWidth;
    qDebug() << "View Port Height: " << viewPortHeight;
    }

    main.cpp

    #include "widget.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
    

    }

    I got the following error on windows 10:

    QWin32PrintEngine::initialize: CreteDC failed (The specified procedure could not be found.)

    I am getting viewport dimensions as zero.

    Whereas on Windows 7, I don't get any such error and also, I got a valid view port dimensions.



  • @NIXIN
    OK, I built your sample and got it working without any errors.
    You have a couple of issues with that code but I guess they are just typos.

    Ui::TestDialog ui; needs to be a pointer -> Ui::TestDialog *ui;
    QPrintPreviewWidget printPreviewWidget; needs to be a pointer -> QPrintPreviewWidget *printPreviewWidget;



  • @kenchan

    Hi,
    Thanks for reverting back, but the errors which you pointed are pointers. I checked in my code, those are pointers.

    Actually I have directly copied and pasted the code to this editor, may be due to that some modifications had taken place.

    However, What values of 'View Port Width' and 'View Port Height' you got??



  • @NIXIN
    View Port Width: 1101
    View Port Height: 771



  • @kenchan
    Did you tried on Windows 10??



  • @NIXIN
    yes, Windows 10 64bit Qt 5.6.0



  • @kenchan

    But for me its not working....


  • Qt Champions 2016

    @NIXIN
    are you sure you have a default printer?



  • @NIXIN
    there must be something wrong with your QT installation, project settings or your runtime env??

    Are you using the Microsoft compiler or something else?



  • I have cute PDF writer....



  • @kenchan
    I am using mingw32bit...



  • @NIXIN
    I have never used it so I can't offer you any advice on that.



  • @kenchan
    Are you using qt-opensource-windows-x86-msvc2015_64-5.6.0.exe installation ?



  • @NIXIN
    I am currently using qt-opensource-windows-x86-msvc2013_64-5.6.0


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.