开发者

Using Qt K* classes with CMake

My standard CMakeLists.txt file for projects that use Qt looks like:

PROJECT(KFileWidgetDemo)

FIND_PACKAGE(Qt4 REQUIRED)
INCLUD开发者_开发知识库E(${QT_USE_FILE})

QT4_WRAP_UI(UISrcs form.ui)
QT4_WRAP_CPP(MOCSrcs form.h)

include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

ADD_EXECUTABLE(KFileWidgetDemo main.cpp form.h form.cpp ${MOCSrcs} ${UISrcs})
TARGET_LINK_LIBRARIES(KFileWidgetDemo ${QT_LIBRARIES})

However, I have always only used Q* classes. Now I need to use KFileWidget, and I am getting errors when compiling:

error: stray ‘\177’ in program
error: stray ‘\1’ in program

Is there a magic CMake command that might fix this?

Thanks,

David


I was under the impression the the K* classes were what Qt named their KDE specific subclasses. I guess that is not quite the case. I got this working by including and linking to KDE4 directly with:

cmake_minimum_required(VERSION 2.6)

PROJECT(KFileWidgetDemo)

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

find_package(KDE4 4.5.0 REQUIRED)
include_directories( ${KDE4_INCLUDES} )

QT4_WRAP_UI(UISrcs form.ui)
QT4_WRAP_CPP(MOCSrcs form.h)

include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

ADD_EXECUTABLE(KFileWidgetDemo main.cpp form.h form.cpp ${MOCSrcs} ${UISrcs})
TARGET_LINK_LIBRARIES(KFileWidgetDemo ${QT_LIBRARIES} ${KDE_LIBRARIES} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS})

Note the key to resolve the linker errors for KUrl was ${KDE4_KFILE_LIBS}.


I had a similar effect when one of my source files was converted to UTF-16 by some IDE. Check the encoding of your files and change them to UTF-8.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜