QtCreator + QT + VTK in Linux

来源:互联网 发布:unity3d 粒子系统瀑布 编辑:程序博客网 时间:2024/04/30 19:40

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


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

123
#include <QVTKWidget.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h>

And these members:

Source code

12
QVTKWidget* vtkWidget;     vtkRenderer* ren;

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

Source code

12345678910
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

1234
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

123
  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. :)
原创粉丝点击