Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Print Preview features fails on Windows 10

Print Preview features fails on Windows 10

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprintpreviewwiwindows10
19 Posts 3 Posters 5.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NIXIN
    wrote on 17 Mar 2017, 04:55 last edited by
    #1

    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.

    M 1 Reply Last reply 17 Mar 2017, 06:54
    0
    • N NIXIN
      17 Mar 2017, 04:55

      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.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 17 Mar 2017, 06:54 last edited by
      #2

      @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.

      1 Reply Last reply
      2
      • N Offline
        N Offline
        NIXIN
        wrote on 20 Mar 2017, 10:18 last edited by
        #3

        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.

        M K 2 Replies Last reply 20 Mar 2017, 10:22
        0
        • N NIXIN
          20 Mar 2017, 10:18

          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.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 20 Mar 2017, 10:22 last edited by
          #4

          @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 ?

          1 Reply Last reply
          1
          • N NIXIN
            20 Mar 2017, 10:18

            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.

            K Offline
            K Offline
            kenchan
            wrote on 20 Mar 2017, 12:23 last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NIXIN
              wrote on 20 Mar 2017, 12:24 last edited by
              #6

              @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.

              K 1 Reply Last reply 20 Mar 2017, 13:10
              0
              • N NIXIN
                20 Mar 2017, 12:24

                @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.

                K Offline
                K Offline
                kenchan
                wrote on 20 Mar 2017, 13:10 last edited by
                #7

                @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;

                1 Reply Last reply
                2
                • N Offline
                  N Offline
                  NIXIN
                  wrote on 20 Mar 2017, 13:47 last edited by
                  #8

                  @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??

                  K 1 Reply Last reply 20 Mar 2017, 13:49
                  0
                  • N NIXIN
                    20 Mar 2017, 13:47

                    @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??

                    K Offline
                    K Offline
                    kenchan
                    wrote on 20 Mar 2017, 13:49 last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      NIXIN
                      wrote on 20 Mar 2017, 13:55 last edited by
                      #10

                      @kenchan
                      Did you tried on Windows 10??

                      K 1 Reply Last reply 20 Mar 2017, 13:56
                      0
                      • N NIXIN
                        20 Mar 2017, 13:55

                        @kenchan
                        Did you tried on Windows 10??

                        K Offline
                        K Offline
                        kenchan
                        wrote on 20 Mar 2017, 13:56 last edited by
                        #11

                        @NIXIN
                        yes, Windows 10 64bit Qt 5.6.0

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          NIXIN
                          wrote on 20 Mar 2017, 13:57 last edited by
                          #12

                          @kenchan

                          But for me its not working....

                          M K 2 Replies Last reply 20 Mar 2017, 13:58
                          0
                          • N NIXIN
                            20 Mar 2017, 13:57

                            @kenchan

                            But for me its not working....

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 20 Mar 2017, 13:58 last edited by
                            #13

                            @NIXIN
                            are you sure you have a default printer?

                            1 Reply Last reply
                            0
                            • N NIXIN
                              20 Mar 2017, 13:57

                              @kenchan

                              But for me its not working....

                              K Offline
                              K Offline
                              kenchan
                              wrote on 20 Mar 2017, 14:00 last edited by
                              #14

                              @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?

                              1 Reply Last reply
                              0
                              • N Offline
                                N Offline
                                NIXIN
                                wrote on 20 Mar 2017, 14:01 last edited by
                                #15

                                I have cute PDF writer....

                                1 Reply Last reply
                                0
                                • N Offline
                                  N Offline
                                  NIXIN
                                  wrote on 20 Mar 2017, 14:02 last edited by
                                  #16

                                  @kenchan
                                  I am using mingw32bit...

                                  K 1 Reply Last reply 20 Mar 2017, 14:03
                                  0
                                  • N NIXIN
                                    20 Mar 2017, 14:02

                                    @kenchan
                                    I am using mingw32bit...

                                    K Offline
                                    K Offline
                                    kenchan
                                    wrote on 20 Mar 2017, 14:03 last edited by
                                    #17

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

                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      NIXIN
                                      wrote on 21 Mar 2017, 05:39 last edited by
                                      #18

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

                                      K 1 Reply Last reply 21 Mar 2017, 06:05
                                      0
                                      • N NIXIN
                                        21 Mar 2017, 05:39

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

                                        K Offline
                                        K Offline
                                        kenchan
                                        wrote on 21 Mar 2017, 06:05 last edited by
                                        #19

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

                                        1 Reply Last reply
                                        0

                                        1/19

                                        17 Mar 2017, 04:55

                                        • Login

                                        • Login or register to search.
                                        1 out of 19
                                        • First post
                                          1/19
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved