简体   繁体   English

使用 cmake 无法让 QPrinter 链接

[英]Trouble getting QPrinter to link using cmake

So I've been trying to get my programs with QPrinter to work compile with cmake+mingw+qt5.2 but I'm having issues: the following test program doesn't compile because it cant find QPrinter which should be part of QtCore所以我一直在尝试让我的程序与 QPrinter 一起使用 cmake+mingw+qt5.2 进行编译,但我遇到了问题:以下测试程序无法编译,因为它找不到应该是 QtCore 一部分的 QPrinter

#include <QPrinter>
#include <QApplication>
#include <windows.h>

int main()
{
    QApplication a( argc, argv );

    return 0;
} // end

this is my cmake file这是我的 cmake 文件

    SET(CMAKE_C_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/gcc.exe)
    SET(CMAKE_CXX_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/g++.exe)
    cmake_minimum_required(VERSION 2.8)

    PROJECT (test_prog)
    add_definitions(-std=c++11)
    SET( test_prog_SRCS test.cpp)
      # Tell CMake to run moc when necessary:
      set(CMAKE_AUTOMOC ON)
      # As moc files are generated in the binary dir, tell CMake
      # to always look for includes there:
      set(CMAKE_INCLUDE_CURRENT_DIR ON)

      # Widgets finds its own dependencies.
      find_package(Qt5Widgets REQUIRED)
      find_package(Qt5Core REQUIRED)
      find_package(Qt5Gui REQUIRED)

    include_directories(
        ${Qt5Widgets_INCLUDE_DIRS}
        ${Qt5Gui_INCLUDE_DIRS}
        ${Qt5Core_INCLUDE_DIRS}
    )

    add_executable(test_prog WIN32  ${test_prog_SRCS})
    target_link_libraries(test_prog ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} )

The Error is:错误是:

test.cpp:1:20: fatal error: QPrinter: No such file or directory test.cpp:1:20: 致命错误: QPrinter: 没有那个文件或目录
#include <QPrinter>

Does anyone know the right incantations to get this to work?有谁知道正确的咒语才能让它发挥作用?

With CMake 2.8.11:使用 CMake 2.8.11:

SET(CMAKE_C_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/gcc.exe)
SET(CMAKE_CXX_COMPILER E:/Qt/Qt5.2.1/Tools/mingw48_32/bin/g++.exe)
cmake_minimum_required(VERSION 2.8.11)

PROJECT (test_prog)
add_definitions(-std=c++11)
SET( test_prog_SRCS test.cpp)
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5PrintSupport REQUIRED)

add_executable(test_prog WIN32  ${test_prog_SRCS})
target_link_libraries(test_prog Qt5::PrintSupport)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM