Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
errors.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtWidgets>
5#include <QtPrintSupport/qtprintsupportglobal.h>
6#if QT_CONFIG(printdialog)
7#include <QPrinter>
8#endif
9
10int main(int argc, char **argv)
11{
12 QApplication app(argc, argv);
13
15 QPrinter printer;
17 printer.setOutputFileName("/foobar/nonwritable.pdf");
19 if (! painter.begin(&printer)) { // failed to open file
20 qWarning("failed to open file, is it writable?");
21 return 1;
22 }
23 painter.drawText(10, 10, "Test");
24 if (! printer.newPage()) {
25 qWarning("failed in flushing page to disk, disk full?");
26 return 1;
27 }
28 painter.drawText(10, 10, "Test 2");
29 painter.end();
31 return 0;
32}
The QApplication class manages the GUI application's control flow and main settings.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false.
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position.
bool end()
Ends painting.
\reentrant
Definition qprinter.h:28
bool newPage() override
Tells the printer to eject the current page and to continue printing on a new page.
@ PdfFormat
Definition qprinter.h:69
void setOutputFormat(OutputFormat format)
Definition qprinter.cpp:549
void setOutputFileName(const QString &)
Sets the name of the output file to fileName.
Definition qprinter.cpp:717
int main()
[0]
#define qWarning
Definition qlogging.h:166
QApplication app(argc, argv)
[0]
QPainter painter(this)
[7]