Below is the code:
Test. H
# # ifndef TEST_H
# define TEST_H
# include & lt; QtWidgets/QMainWindow>
# include "ui_test. H"
#include
The class vtkImageViewer2;
The class vtkRenderer;
//class QPushButton;
The class QVTKWidget;
The class test: public QMainWindow
{
Q_OBJECT
Public:
The test (QWidget * parent=0);
To test ();
Private:
Ui: : testClass Ui;
Private slots:
Void onOpenSlot ();
Private:
VtkSmartPointerVtkSmartPointer M_pRenderer;
//QPushButton pushButton.
QVTKWidget m_QVTKWidget;
};
# endif//TEST_H
Test. The CPP
# include "test. H"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
The test: test (QWidget * parent)
: QMainWindow (parent)
{
UI. SetupUi (this);
M_pImageViewer=vtkSmartPointerM_pRenderer=vtkSmartPointer : : New ();
//set the renderer m_QVTKWidget
M_QVTKWidget. GetRenderWindow () - & gt; AddRenderer (m_pRenderer);
//connected to the open signal with the corresponding slot
The connect (UI) pushButton, SIGNAL (triggered ()), and this, SLOT (onOpenSlot ()));
}
The test: : ~ test ()
{
}
Void test: : onOpenSlot ()
{
QString filter;
The filter="JPEG image file (*. * JPG. JPEG)";
QDir dir.
QString fileName=QFileDialog: : getOpenFileName (this, QString (tr (" open image ")), dir. AbsolutePath (), the filter).
If (fileName. IsEmpty ()==true) return;
//support with Chinese path read
QByteArray ba=fileName. ToLocal8Bit ();
Const char * fileName_str=co data ();
//vtkIPEGReader read JPG image
VtkSmartPointerReader=vtkSmartPointer : : New ();
Reader - & gt; SetFileName (fileName_str);
//to as m_pImageViewer input, the output of a reader and set the m_ImageViewer associated with the renderer m_pRenderer
M_pImageViewer - & gt; SetInputData (reader - & gt; GetOutput ());
M_pImageViewer - & gt; UpdateDisplayExtent ();
M_pImageViewer - & gt; SetRenderWindow (m_QVTKWidget GetRenderWindow ());
M_pImageViewer - & gt; SetRenderer (m_pRenderer);
M_pImageViewer - & gt; SetupInteractor (m_QVTKWidget GetRenderWindow () - & gt; GetInteractor ());
M_pImageViewer - & gt; SetSliceOrientationToXY ();//default is the direction of
M_pImageViewer - & gt; GetImageActor () - & gt; InterpolateOff ();
M_pRenderer - & gt; ResetCamera ();
M_pRenderer - & gt; DrawOn ();
M_QVTKWidget. GetRenderWindow () - & gt; Render ();
}
The main. CPP
# include "test. H"
# include & lt; QtWidgets/QApplication>
Int main (int arg c, char * argv [])
{
QApplication a (arg c, argv);
The test w;
Baron how ();
Return a.e xec ();
}
An error
Test. Obj: error LNK2019: cannot resolve the external symbol "__declspec (dllimport) public: virtual __thiscall QVTKWidget: : ~ QVTKWidget (void)" (__imp_?? 1 qvtkwidget @ @ UAE @ XZ), the symbol in the function of "public: virtual __thiscall test: : ~ test (void)" (?????? 1 test @ @ UAE @ XZ) referenced
1> Test. Obj: error LNK2019: cannot resolve the external symbol "__declspec (dllimport) public: __thiscall QVTKWidget: : QVTKWidget (class QWidget *, class QFlags) "(__imp_?? 0 qvtkwidget @ @ QAE @ PAVQWidget @ @ V? $QFlags @ W4WindowType @ Qt @ @ @ @ @ Z), the symbol in the function of "public: __thiscall test: : test (class QWidget *)" (?????? 0 test @ @ QAE @ PAVQWidget @ @ @ Z) referenced
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "public: virtual struct QMetaObject const * __thiscall QVTKWidget: : metaObject (void) const" (? MetaObject @ QVTKWidget @ @ UBEPBUQMetaObject @ @ XZ)
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "public: virtual void * __thiscall QVTKWidget: : qt_metacast (char const *)" (? Qt_metacast @ QVTKWidget @ @ UAEPAXPBD @ Z)
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "public: virtual int __thiscall QVTKWidget: : qt_metacall (enum QMetaObject: : Call, int, void * *)" (? Qt_metacall @ QVTKWidget @ @ UAEHW4Call @ QMetaObject @ @ HPAPAX @ Z)
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "protected: virtual bool __thiscall QVTKWidget: : event (class QEvent *)" (? The event @ QVTKWidget @ @ MAE_NPAVQEvent @ @ @ Z)
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "protected: virtual void __thiscall QVTKWidget: : mousePressEvent (class QMouseEvent *)" (? MousePressEvent @ QVTKWidget @ @ MAEXPAVQMouseEvent @ @ @ Z)
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "protected: virtual void __thiscall QVTKWidget: : mouseReleaseEvent (class QMouseEvent *)" (? MouseReleaseEvent @ QVTKWidget @ @ MAEXPAVQMouseEvent @ @ @ Z)
1> Test. Obj: error LNK2001: cannot resolve the external symbol of "protected: virtual void __thiscall QVTKWidget: : mouseMoveEvent (class QMouseEvent *)" (? MouseMoveEvent @ QVTKWidget @ @ MAEXPAVQMouseEvent @ @ @ Z)
1> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull