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
Forum Updated to NodeBB v4.3 + New Features

Print Preview features fails on Windows 10

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprintpreviewwiwindows10
19 Posts 3 Posters 6.3k Views 3 Watching
  • 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.
  • NIXINN NIXIN

    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.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on 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
    • NIXINN NIXIN

      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 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
      • NIXINN Offline
        NIXINN Offline
        NIXIN
        wrote on 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
        0
        • NIXINN NIXIN

          @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 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
          • NIXINN Offline
            NIXINN Offline
            NIXIN
            wrote on 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
            0
            • NIXINN NIXIN

              @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 last edited by
              #9

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

              1 Reply Last reply
              0
              • NIXINN Offline
                NIXINN Offline
                NIXIN
                wrote on last edited by
                #10

                @kenchan
                Did you tried on Windows 10??

                K 1 Reply Last reply
                0
                • NIXINN NIXIN

                  @kenchan
                  Did you tried on Windows 10??

                  K Offline
                  K Offline
                  kenchan
                  wrote on last edited by
                  #11

                  @NIXIN
                  yes, Windows 10 64bit Qt 5.6.0

                  1 Reply Last reply
                  0
                  • NIXINN Offline
                    NIXINN Offline
                    NIXIN
                    wrote on last edited by
                    #12

                    @kenchan

                    But for me its not working....

                    mrjjM K 2 Replies Last reply
                    0
                    • NIXINN NIXIN

                      @kenchan

                      But for me its not working....

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @NIXIN
                      are you sure you have a default printer?

                      1 Reply Last reply
                      0
                      • NIXINN NIXIN

                        @kenchan

                        But for me its not working....

                        K Offline
                        K Offline
                        kenchan
                        wrote on 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
                        • NIXINN Offline
                          NIXINN Offline
                          NIXIN
                          wrote on last edited by
                          #15

                          I have cute PDF writer....

                          1 Reply Last reply
                          0
                          • NIXINN Offline
                            NIXINN Offline
                            NIXIN
                            wrote on last edited by
                            #16

                            @kenchan
                            I am using mingw32bit...

                            K 1 Reply Last reply
                            0
                            • NIXINN NIXIN

                              @kenchan
                              I am using mingw32bit...

                              K Offline
                              K Offline
                              kenchan
                              wrote on 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
                              • NIXINN Offline
                                NIXINN Offline
                                NIXIN
                                wrote on last edited by
                                #18

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

                                K 1 Reply Last reply
                                0
                                • NIXINN NIXIN

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

                                  K Offline
                                  K Offline
                                  kenchan
                                  wrote on last edited by
                                  #19

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

                                  1 Reply Last reply
                                  0

                                  • Login

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