[英]Qt Cannot open include file: 'QPrinter'
I am new to Qt.我是 Qt 的新手。 Downloaded source code for a Qt application of SourceForge, and tried to build and run it.
下载 SourceForge 的 Qt 应用程序的源代码,并尝试构建和运行它。 After working through a few similar problems by adding
QT +=
statements to .pro files, I am stuck on this one:通过将
QT +=
语句添加到 .pro 文件解决了一些类似的问题后,我被困在这个问题上:
On attempting to build in Qt Creator, I get errors saying在尝试在 Qt Creator 中构建时,我收到错误消息
error: C1083: Cannot open include file: 'QPrinter': No such file or directory
错误:C1083:无法打开包含文件:'QPrinter':没有这样的文件或目录
I tried adding QT += printsupport
to the .pro file, cleaning, and rebuilding, but that gives this error我尝试将
QT += printsupport
添加到 .pro 文件、清理和重建,但这给出了这个错误
Error: dependent '..\..\..\..\..\..\..\..\..\..\..\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport\qtprintsupportglobal.h' does not exist."
错误:依赖 '..\..\..\..\..\..\..\..\..\..\..\Qt\Qt5.1.1\5.1.1\msvc2012_64\include \QtPrintSupport\qtprintsupportglobal.h' 不存在。”
When I go to C:\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport
, qtprintsupportglobal.h IS THERE!当我去
C:\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport
时, qtprintsupportglobal.h 就在那里!
您必须将 QPrinter 支持添加到项目的 .pro 文件中:
QT += printsupport
In my case the solution was to就我而言,解决方案是
Delete the shadow build directory and build again
删除影子构建目录并重新构建
after adding printsupport
, as @KubaOber suggests in the comments.添加
printsupport
后,正如@KubaOber 在评论中所建议的那样。
Easy mistake to make: After you edit your .pro容易犯的错误:编辑 .pro 后
QT += printsupport
You have to SAVE the file before your .h will be aware of it.您必须先保存文件,然后您的 .h 才会知道它。
Because QMake will eventually be dropped in favor of CMake, here's the solution for CMake users:因为 QMake 最终会被 CMake 取代,所以这里是 CMake 用户的解决方案:
Pass PrintSupport
to the find_package
call, to the right side of COMPONENTS
, like in this example:将
PrintSupport
传递给find_package
调用,在COMPONENTS
的右侧,如下例所示:
find_package(Qt5 ${QT5_MIN_VERSION} REQUIRED COMPONENTS Core Gui Qml QuickControls2 PrintSupport)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.