简体   繁体   English

使用cmake构建Qt 4项目时出错

[英]Error while building a Qt 4 project using cmake

I have create a simple Qt 4 project, and now, I want to make use of CMake as the build system. 我已经创建了一个简单的Qt 4项目,现在,我想使用CMake作为构建系统。 My project files are as follow: 我的项目文件如下:

├── about.cpp
├── about.h
├── about.ui
├── alldeb_en.ts
├── alldeb_id.ts
├── AllDebInstaller.pro
├── CMakeLists.txt
├── dialog.cpp
├── dialog.h
├── dialog.ui
└── main.cpp

My CMakeLists.txt file is: 我的CMakeLists.txt文件是:

cmake_minimum_required(VERSION 2.8.9)
PROJECT(alldeb-installer)

set(CMAKE_AUTOMOC ON)

FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})

QT4_WRAP_UI(UISrcs dialog.ui about.ui)
#QT4_WRAP_CPP(MOCSrcs dialog.h about.h)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

ADD_EXECUTABLE(alldeb-installer main.cpp dialog.cpp about.cpp ${MOCSrcs} ${UISrcs})
TARGET_LINK_LIBRARIES(alldeb-installer ${QT_LIBRARIES})

ADD_LIBRARY(terjemah ${sources}
${UISrcs})

qt4_create_translation(qm_files
${terjemah_SRCS} alldeb_en.ts alldeb_id.ts
)

install(TARGETS alldeb-installer DESTINATION bin)

But something still messed. 但是仍然有些混乱。 I don't know what's wrong with about.cpp. 我不知道about.cpp有什么问题。
the 'error: stray '\\nnn' in program' appear many times. “错误:程序中出现杂散'\\ nnn'”出现了很多次。
here is the screenshot: 这是屏幕截图:

在此处输入图片说明

image: http://i62.tinypic.com/1gm6ty.png 图片: http//i62.tinypic.com/1gm6ty.png

Please someone explain it. 请有人解释。 Thanks. 谢谢。

EDIT 编辑
oh, it's surprising and embarassing, I've found that about.cpp contains many unknown characters. 令人惊讶和尴尬的是,我发现about.cpp包含许多未知字符。
here is the screenshot: 这是屏幕截图:

image: http://i62.tinypic.com/2iql2qh.png 图片: http : //i62.tinypic.com/2iql2qh.png

it must be because the wrong CMakeLists.txt configuration before. 一定是因为之前的CMakeLists.txt配置错误。

but actually about.cpp only contains: 但实际上about.cpp仅包含:

#include "about.h"
#include "ui_about.h"

About::About(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::About)
{
    ui->setupUi(this);
}

About::~About()
{
    delete ui;
}

This is not a cmake issue, but corruption with your about.cpp file. 这不是cmake问题,而是about.cpp文件损坏。 It has got stray characters for one reason or another. 它由于某些原因或其他原因而出现了流浪汉。 The solution is "uncorrupt it", and then it will work with the same cmake file. 解决方案是“不破坏它”,然后它将与相同的cmake文件一起使用。

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

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