I am trying to run the official example for generating pdf with Qt from QtWiki but it crashes with code -1073740940. It happens at this line: QPrinter printer(QPrinter::PrinterResolution);
The printsupport is added to the project file.
I am not changing anything in the example code:
#include <QtWidgets>
#ifndef QT_NO_PRINTER
#include <QPrinter>
#endif
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Export PDF", QString(), "*.pdf");
if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }
QPrinter printer(QPrinter::PrinterResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(fileName);
QTextDocument doc;
doc.setHtml("<h1>Hello, World!</h1>\n<p>Lorem ipsum dolor sit amet, consectitur adipisci elit.</p>");
doc.setPageSize(printer.pageRect().size()); // This is necessary if you want to hide the page number
doc.print(&printer);
}
I have "Microsoft print to pdf" in devices.
What could be the reason for the crash and how to fix it?
// Added after
My setup:
Qt 5.14.1
MinGW 64 bit
Win 10 64 bit
Debugger stack trace:
1 ntdll!RtlIsNonEmptyDirectoryReparsePointAllowed 0x7ffa1b1b91b3
2 ntdll!RtlpNtMakeTemporaryKey 0x7ffa1b1c15e2
3 ntdll!RtlpNtMakeTemporaryKey 0x7ffa1b1c18ea
4 ntdll!RtlpNtMakeTemporaryKey 0x7ffa1b1ca8a9
5 ntdll!RtlGetCurrentServiceSessionId 0x7ffa1b10253a
6 ntdll!RtlGetCurrentServiceSessionId 0x7ffa1b100790
7 ntdll!RtlFreeHeap 0x7ffa1b0ffb91
8 ntdll!RtlpNtMakeTemporaryKey 0x7ffa1b1c53c9
9 ntdll!memset 0x7ffa1b175670
10 ntdll!RtlGetCurrentServiceSessionId 0x7ffa1b100790
11 ntdll!RtlFreeHeap 0x7ffa1b0ffb91
12 msvcrt!free 0x7ffa19189cfc
13 QWindowsPrintDevice::defaultPageSize() const 0x6f882e41
14 QPrintDevice::defaultPageSize() const 0x6df43efd
15 QWin32PrintEngine::QWin32PrintEngine(QPrinter::PrinterMode, QString const&) 0x6df528b2
16 QWindowsPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode, QString const&) 0x6f88169a
17 QPrinterPrivate::initEngines(QPrinter::OutputFormat, QPrinterInfo const&) 0x6df4a523
18 QPrinterPrivate::init(QPrinterInfo const&, QPrinter::PrinterMode) 0x6df4a70e
19 QPrinter::QPrinter(QPrinter::PrinterMode) 0x6df4a818
20 main main.cpp 13 0x4016cc
This is not a solution but a workaround. Change your default printer. For some reason the QPrinter constructor crashes when certain printers are the system default.
Related
I am currently having some trouble debugging a program that starts processes via QProcess.
Simply executing the binary without dbg works just fine but when I try to debug the executable with gdb I am getting a SIGTRAP when the process has started.
After that the stack always shows '??' instead of function names.
When continuing I get a SIGILL.
I found out that the trap is not caused when no breakpoint is set.
In my project I also get following output:
Probes-based dynamic linker interface failed.
I am not sure whether this is related to loaded plugins or libraries.
The problem can be reproduced (except from the " Probes-based dynamic linker interface failed." output) with the following code:
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QProcess proc;
QString exe = "echo";
QStringList arguments;
arguments << "Test";
proc.start(exe, arguments);
if (!proc.waitForFinished()) {
qDebug() << "failed to start" << proc.exitCode() << proc.errorString();
}
qDebug() << "process finished";
qDebug() << proc.readAllStandardOutput();
return a.exec();
}
My OS is arch linux (up to date)
Qt5: qt5-base 5.15.1-1
GDB: gdb 9.2-1
clang++: clang 10.0.1-1
Does anybody have an idea what is causing the SIGTRAP when debugging with dbg?
I need to migrate qt/4.8.6 code to qt/5.9 . I am struggling with using print statement within QScriptEngine evaluate statement. In simplified form implementation looks like:
#include <iostream>
#include <QApplication>
#include <QtScript>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QScriptEngine engine;
std::cout << "Hello, world!\n";
engine.evaluate("print('test\n\n')");
}
.pro file
CONFIG += qt
CONFIG += console
SOURCES += main.cc
QT += widgets
QT += script
sources.files = main.cpp qscript.pro
INSTALLS += sources
->output to console:
Hello, world!
in qt/4.8.6 it prints out evaluated print statement to console "Hello, world! test", whereas in qt/5.9 it prints only "Hello, world!"
Any idea, why using print command is not working? Note, I need to implement printing to stdout by using js scripting+ evaluate.
I want to use an SDK I got for using a scanner. I'm using Qt 5.3 with MingW32 (on Windows 7).
The very first test I wanted to build should just print the SDK version.
Here is my project file
QT += core
QT -= gui
TARGET = Kojak1
CONFIG += console
CONFIG -= app_bundle
KOJAKDIR = "C:/Program Files/Integrated Biometrics/IBScanUltimateSDK_x64"
TEMPLATE = app
INCLUDEPATH += $$KOJAKDIR/Include
SOURCES += main.cpp
LIBS +=-L$$KOJAKDIR/lib/ -lIBScanUltimate
and here is the source code
#include <QCoreApplication>
#include "stdio.h"
#include <windows.h>
#include "IBScanUltimateApi.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
IBSU_SdkVersion sdk_version;
IBSU_GetSDKVersion(&sdk_version);
printf("%s %s",sdk_version.File,sdk_version.Product);
return a.exec();
}
Unforturnately I get the message
D:\devt\QTProjects\Kojak1\main.cpp:10: error: undefined reference to `IBSU_GetSDKVersion#4'
when trying to compile the program.
My lib directory does contain IBScanUltimate.lib and IBScanUltimate.dll.
I've tried to embed emacs in a Qt Application using QX11EmbedContainer, and works but with two important exception. First of all, here is the code:
#include <QX11EmbedWidget>
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QX11EmbedContainer container;
container.show();
container.resize(500, 500);
QProcess* process = new QProcess(&container);
QString executable("emacsclient");
QStringList arguments;
arguments << "--parent-id" << QString::number(container.winId());
process->start(executable, arguments);
int status = app.exec();
process->close();
return status;
}
And the compilation and execution line (and the previous thrown of the emacs server):
$ emacs -q --daemon &
// filtered output
$ g++ test.cpp -lQtGui -lQtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4
$ ./a.out
And finally, the result:
But, when or if I try to write something in the minibuffer, the size of the widget is collapsed, and the focus is also lost:
If I make click in the (now shorter) widget, I can continue working with emacs without problems, but I should resize the window in order to emacs is expanded other time as originally.
Where is the problem?
Try using a layout.
Here is the Qt5 documentation on layout management.
hi i'm just trying to compile an easy project in qt
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton bouton("Salut les ZĂ©ros, la forme ?");
bouton.show();
return app.exec();
}
but i have this error : /home/eid/test/easyprojet/main.cpp:1: error: QApplication: No such file or directory
can anyone help me ?
sorry for my english
In Qt5, it resides in , while in Qt4 it was .
In Qt5 you need to add QT += widgets to your .pro file.
It may be also because the project is not in the workspace of QT creator.
It happened with me before.
so,try to put the project in the workspace .