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.
-
@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-dialogAlternatively, have a look at the exe and plugins with http://www.dependencywalker.com/
and see if they are missing any DLLS. -
@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.ioAlso, just for sanity. You did try to print from some other non Qt app to test Windows 100% happy ?
-
@mrjj
Hi,
I have developed a sample application which gives the same problemwidget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <Qpainter>namespace Ui {
class Widget;
}class Widget : public QWidget
{
Q_OBJECTpublic:
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_OBJECTpublic:
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; -
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??