如何设置一个简单的CGAL+Qt程序
How can I set up a simple CGAL + Qt program
我想设置一个简单的CGAL+Qt程序。简而言之,我想采取以下措施:
https://github.com/CGAL/cgal/blob/master/Arrangement_on_surface_2/examples/Arrangement_on_surface_2/conics.cpp
并使用Qt打印出它的可视化。我没有问题编译以上:
cgal_create_CMakeLists -c Core
cmake -DCGAL_DIR=/usr/share/CGAL/ .
make
并且已经能够使用qmake编译各种Qt程序,但我很难在conics.cpp文件中使用Qt。
我的问题是:
- 我需要包含哪些Qt库
- 如何使用插入器将arr插入Qt小部件流
- 如何使用cmake设置和运行
更新
我一直在想如何用Qt头编译一个程序。在Polygon演示之后,我添加了:
// Qt headers
#include <QtGui>
#include <QString>
#include <QFileDialog>
#include <QInputDialog>
#include <QGraphicsLineItem>
到conics.cpp。我也没有运气:
cgal_create_cmake_script
或:
cgal_create_CMakeLists -c Core:Qt5
目前正在进行的工作是将Polygon演示中的CMakeLists.txt修改为:
project (Qt_Demo)
cmake_minimum_required(VERSION 3.1)
if(NOT POLICY CMP0070 AND POLICY CMP0053)
# Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning.
cmake_policy(SET CMP0053 OLD)
endif()
find_package(CGAL COMPONENTS Qt5 Core)
include(${CGAL_USE_FILE})
find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg)
include_directories (BEFORE ../../include)
if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND )
add_definitions(-DQT_NO_KEYWORDS)
if( CGAL_Core_FOUND)
add_definitions(-DCGAL_USE_CORE)
endif()
#--------------------------------
# Demo: Polygon_2
#--------------------------------
# UI files (Qt Designer files)
#qt5_wrap_ui( DT_UI_FILES Polygon_2.ui )
# qrc files (resources files, that contain icons, at least)
#qt5_add_resources ( CGAL_Qt5_RESOURCE_FILES ./Polygon_2.qrc )
# use the Qt MOC preprocessor on classes that derives from QObject
qt5_generate_moc( conics.cpp "${CMAKE_CURRENT_BINARY_DIR}/conics.moc" )
# add_library( CGAL SHARED IMPORTED )
# SET_PROPERTY(TARGET CGAL PROPERTY IMPORTED_LOCATION ${CGAL_LIBRARY} )
# The executable itself.
add_executable ( conics conics.cpp conics.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ${CGAL_Qt5_RESOURCE_FILES} ${CGAL_Qt5_MOC_FILES} )
qt5_use_modules(conics Xml Script OpenGL Svg)
add_to_cached_list( CGAL_EXECUTABLE_TARGETS conics )
# Link with Qt libraries
target_link_libraries( conics ${QT_LIBRARIES} )
# And with CGAL libraries
target_link_libraries( conics ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
else()
message(STATUS "NOTICE: This demo requires CGAL, CGAL_Core, and Qt5, and will not be compiled.")
endif()
真的,应该有一个更简单的方法!
- "我需要包含哪些Qt库?"您需要来自Qt的以下库
#include <QtGui>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
除此之外,您还需要一些CGAL::Qt库来支持CGAL数据结构
#include <CGAL/Qt/GraphicsViewNavigation.h>
您还需要一个自定义图形项来表示Arrangement_2而不是CCD_ 1。
CGAL中的Arrangement_2项由"顶点"、"边"answers"面"的组合表示。因此,您需要一个自定义QGraphicsItem来在Qt中的场景上显示Arrangement_2。
在CGAL Demo中,您可以在Arrangement_2GraphicsItem.h中找到一个预定义的图形项,该项可用于显示圆锥的排列。
- 如何使用插入器将arr插入Qt小部件流
一旦有了Arrangement_2GraphicsItem
,就可以将对arr的引用传递到图形项中,并将图形项添加到Qt场景中。
arr_gi = new CGAL::Qt::ArrangementGraphicsItem<Arrangement_2>(&arr);
scene.addItem(arr_gi);
- 如何使用CMake进行设置和运行
您的CMakeLists.txt应该如下所示:
cmake_minimum_required (VERSION 3.8)
project(conics)
find_package(Boost COMPONENTS thread system REQUIRED)
find_package(CGAL REQUIRED COMPONENTS Core Qt5)
find_package(Qt5 QUIET COMPONENTS Qt5 Core)
# Add source to this project's executable.
add_executable (conics
conics.cpp
ArrangementGraphicsItem.h
ArrangementPainterOstream.h #ArrangementGraphicsItem dependencies
ArrangementTypes.h
Utils.h
${CGAL_Qt5_RESOURCE_FILES} ${CGAL_Qt5_MOC_FILES})
qt5_use_modules(conics Xml Script OpenGL Svg)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(conics CGAL::CGAL_Core CGAL::CGAL CGAL::CGAL_Qt5 ${Boost_LIBRARIES})
相关文章:
- 如何设置一个简单的CGAL+Qt程序
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- Qt的新信号/时隙语法问题 - 连接到一个简单的函数
- 通过此指针访问时的成员差异和自身的成员指针(简单的 QT 示例问题)
- 请解释为什么这个简单的C++(Qt)代码如此奇怪
- 简单的Qt视频流应用程序,只有声音,没有视频(白屏)
- 链接器错误在简单的QT C 应用程序中
- 简单的QT从文本文件程序中读取不编译
- 将一个简单的Qt程序移植并运行到FriendlyARM嵌入式设备
- CGAL Qt 链接器错误
- 在一个使用ffmpeg的非常简单的qt应用程序中出现分段错误
- QProcess::terminate() 不适用于简单的 Qt 应用程序作为 Windows XP 下的子进程
- 最简单的Qt对话框
- 最简单的QT TCP服务器
- 最简单的QT TCP客户端
- 添加简单的Qt UI到现有的c++代码(非Qt)
- 简单的Qt项目与openCV瞬间崩溃
- 如何在C4Droid中编译简单的Qt 5.2项目
- 与Visual Studio 2010中的MD相反,无法在MT模式下编译简单的Qt程序
- 我无法构建和运行一个简单的Qt 5应用程序