QtCreator + QT + VTK in Linux

这个挺好,有空再翻译一下!转自这里


QtCreator + QT + VTK in Linux

Hi, just wanted to share my experience on a jump start with using Qt+VTK.
As I don't have experience with using Qt I decided to go the easiest possible way - downloaded Qt4 and the QtCreator. 
The steps I took next:
1. Built Qt4 from source and installed it.
2. Added /usr/local/Trolltech to my PATH environment variable
3. Downloaded the source for VTK 5.4
4. Launched ccmake in the root of the source tree. 
5. Switched ON VTK_USE_GUISUPPORT VTK_USE_QVTK.
6. Pressed "c" to configure in ccmake, and specified the version of Qt 4.0. 
7. After configuring in ccmake, launched cmake, and then make and make install.
8. The needed QVTKWidget.h will be in the /usr/bin/local/include/vtk-5.4.
9. Now we launch QtCreator and create the simple application.
10. In the mainwindow.h I add these headers:

Source code

1
2
3
#include <QVTKWidget.h> 
#include <vtkRenderer.h> 
#include <vtkRenderWindow.h>

And these members:

Source code

1
2
QVTKWidget* vtkWidget;     
vtkRenderer* ren;

11. In the mainwindow.cpp I added this code in the constructor:

Source code

1
2
3
4
5
6
7
8
9
10
MainWindow::MainWindow(QWidget *parent)     
: QMainWindow(parent), ui(new Ui::MainWindowClass) {     
ui->setupUi(this);     
vtkWidget = new QVTKWidget(this,QFlag(0));     
ui->verticalLayout->addWidget(vtkWidget);     
ui->verticalLayout->update();     
ren = vtkRenderer::New();     
vtkWidget->GetRenderWindow()->AddRenderer(ren);     
ren->SetBackground(1.0,0,0);     
ren->Render(); }

And destructor:

Source code

1
2
3
4
MainWindow::~MainWindow() {     
ren->Delete();     
delete vtkWidget;     
delete ui;  }

As you see above I have added a verticalLayout to my form - it has some more controls, and the widget I am adding goes to the bottom. 

12. In the .pro file I added these:

Source code

1
2
3
  LIBS    += -L/usr/local/lib/vtk-5.4 -lvtkCommon -lvtksys -lQVTK -lvtkQtChart -lvtkViews -lvtkWidgets -lvtkInfovis -lvtkRendering -lvtkGraphics -lvtkImaging -lvtkIO -lvtkFiltering -lvtklibxml2 -lvtkDICOMParser -lvtkpng -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg -lvtkalglib -lvtkexpat -lvtkverdict -lvtkmetaio -lvtkNetCDF -lvtksqlite -lvtkexoIIc -lvtkftgl -lvtkfreetype -lvtkHybrid  

INCLUDEPATH += /usr/local/include/vtk-5.4

13. In the Project->Build settings->Build environment I added a variable LD_LIBRARY_PATH = /usr/local/lib/vtk-5.4 - so that when you launch the application the dynamic linker finds the libraries.
14. After building and running (Press [F5] in Qt creator) it should show you a red QVTKWidget.  :)
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值