15

I am new to Qt. Downloaded source code for a Qt application of SourceForge, and tried to build and run it. After working through a few similar problems by adding QT += statements to .pro files, I am stuck on this one:

On attempting to build in Qt Creator, I get errors saying

error: C1083: Cannot open include file: 'QPrinter': No such file or directory

I tried adding QT += printsupport to the .pro file, cleaning, and rebuilding, but that gives this error

Error: dependent '..\..\..\..\..\..\..\..\..\..\..\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport\qtprintsupportglobal.h' does not exist."

When I go to C:\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport, qtprintsupportglobal.h IS THERE!

ymoreau
  • 3,402
  • 1
  • 22
  • 60
Matt M
  • 151
  • 1
  • 1
  • 6

4 Answers4

22

You have to add QPrinter Support to your project's .pro file:

QT += printsupport
Jamal Khan
  • 471
  • 2
  • 5
6

In my case the solution was to

Delete the shadow build directory and build again

after adding printsupport, as @KubaOber suggests in the comments.

Pavel
  • 698
  • 1
  • 11
  • 20
1

Because QMake will eventually be dropped in favor of CMake, here's the solution for CMake users:

Pass PrintSupport to the find_package call, to the right side of COMPONENTS, like in this example:

find_package(Qt5 ${QT5_MIN_VERSION} REQUIRED COMPONENTS Core Gui Qml QuickControls2 PrintSupport)
Javier Cordero
  • 556
  • 7
  • 14
0

Easy mistake to make: After you edit your .pro

QT       += printsupport

You have to SAVE the file before your .h will be aware of it.

frozenjim
  • 746
  • 5
  • 11