Qt创建pdf示例 - 无法使其工作
Qt create pdf example - can't get it to work
我看了一些例子,决定实现其中一个。它可以编译并且在运行时不会崩溃,但是它不会创建pdf,它会抛出一些错误(我不明白(。问题是哪里有错误以及如何删除它?
项目代码:
#-------------------------------------------------
#
# Project created by QtCreator 2013-06-08T10:07:11
#
#-------------------------------------------------
QT += core
QT -= gui
QT += printsupport
TARGET = PDFPrintMaybe
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
以及来源本身:
#include <QTextDocument>
#include <QPrinter>
#include <QApplication>
int main( int argc, char **argv )
{
QApplication app( argc, argv );
QTextDocument doc;
doc.setHtml( "<p>A QTextDocument can be used to present formatted text "
"in a nice way.</p>"
"<p align=center>It can be <b>formatted</b> "
"<font size=+2>in</font> <i>different</i> ways.</p>"
"<p>The text can be really long and contain many "
"paragraphs. It is properly wrapped and such...</p>" );
QPrinter printer;
printer.setOutputFileName("C:\Users\SameTime\Desktop");
printer.setOutputFormat(QPrinter::PdfFormat);
doc.print(&printer);
printer.newPage();
return 0;
}
最后,错误本身:
QPainter:: begin(): Returned false
"C:\Users\SameTime\Desktop"
可能是指现有文件夹,而不是文件名。
您应该指定您的 pdf 文件名,例如
"C:\Users\SameTime\Desktop\1.pdf"
并确保文件的路径存在且可访问。
否则,sustem将无法将pdf装箱并打印(即在pdf画布上绘画(
相关文章:
- 如何创建一个类,以便向量工作 std::vector<MyClass<int>> v{ 1,2,3 };
- 使用 stl 库创建图形是如何工作的?
- 为什么在C++中使用关系运算符创建的模板函数不能对字符串正常工作?
- ZeroMQ 在使用 std::thread 创建工作线程时崩溃
- 使用程序生成来创建磁盘,但纹理无法正常工作
- .exe应用程序在windows10中创建新模块时抛出错误,但在windows7中工作正常
- 此类模板的对象创建如何工作?
- 创建链表,但无法按 CPP 的预期工作
- MPI - 当数组初始化值必须为常量时,如何为工作线程创建部分数组
- 当主GUI线程被阻塞时,如何从工作线程创建无模式对话框
- 使用C++的内置队列类在我创建的类中工作
- 在 CDialog 派生类上创建使用 VS2015 CLR 返回 0,在 VC++ 6 中工作正常
- 让QtWebKit在Qt创建器中工作
- 创建不需要任何进一步安装即可在其他计算机上工作的可执行文件?
- 为什么从 lambda 创建的 std::函数在捕获的变量超出范围后工作
- 如何在 C++ 中创建一个类,使其像本机 int 类一样工作
- 在linux下使用boost::thread创建一个boost::asio工作线程
- 如何创建一个在单独的方法中工作的c++随机正态分布
- 我在 C++ 中创建了一个列表容器类,但它没有按预期工作
- 如何正确关闭为使用IOCP创建的工作线程