简体   繁体   English

Qt 无法打开包含文件:'QPrinter'

[英]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.

相关问题 无法使用Qt打开包含文件:“无此文件或目录” - Cannot open include file with Qt: “No such file or directory” Qt无法在Windows上打开包含文件 - Qt cannot open include file on Windows Qt:无法打开包含文件:'QtSql':没有这样的文件或目录 - Qt : Cannot open include file: 'QtSql': No such file or directory Qt 无法打开包含文件:'QNetworkAccessManager':没有这样的文件或目录 - Qt Cannot open include file: 'QNetworkAccessManager': No such file or directory Qt Creator问题:无法打开包含文件:“ windows.h” - Qt Creator issue : Cannot open include file: ‘windows.h’ Qt MySQL -------无法打开包含文件:'mysql.h': - Qt MySQL -----— Cannot open include file: 'mysql.h': Qt 5迁移 - 无法打开包含文件:'ui_mainwindow.h' - Qt 5 migration - Cannot open include file: 'ui_mainwindow.h' Qt包括另一个项目的类(无法打开包含文件:'foo.h') - Qt include Class of another Project (Cannot open include file: 'foo.h') 为什么Qt不识别我的头文件? 无法打开包含文件没有这样的文件或目录 - Why doesn't Qt recognize my header file? cannot open include file No such file or directory 尝试使用 MSVC 从源代码构建 qt 创建者:无法打开包含文件:'stddef.h':没有这样的文件或目录 - Trying to build qt creator from source with MSVC: Cannot open include file: 'stddef.h': No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM