【发布时间】:2014-04-21 06:27:23
【问题描述】:
我已经创建了一个简单的 Qt 4 项目,现在,我想使用 CMake 作为构建系统。我的项目文件如下:
├── about.cpp
├── about.h
├── about.ui
├── alldeb_en.ts
├── alldeb_id.ts
├── AllDebInstaller.pro
├── CMakeLists.txt
├── dialog.cpp
├── dialog.h
├── dialog.ui
└── main.cpp
我的 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)
但还是有些问题。我不知道 about.cpp 有什么问题。
'错误:程序中的流浪'\ nnn'出现很多次。
这是屏幕截图:
图片:http://i62.tinypic.com/1gm6ty.png
请有人解释一下。谢谢。
编辑
哎呀,好奇怪好尴尬,我发现about.cpp里面有很多不知名的字符。
这是屏幕截图:
图片:http://i62.tinypic.com/2iql2qh.png
一定是因为之前的CMakeLists.txt配置错误。
但实际上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;
}
【问题讨论】:
-
它可能与粘贴的cmake文件无关,而是您的代码。检查它是否出于某种原因有一些杂散字符。您可以尝试在此处粘贴 about.cpp。
-
以前,我在谷歌上搜索过,但我确信 about.cpp 不包含杂散字符。但是在我检查之后,你是对的,它有杂散字符。顺便说一句,实际上我想要你对我的 Cmakelists 的意见。那样可以吗?
-
没关系。我个人会为源文件使用一个变量,但这不是什么大问题。