Qt / VTK:没有合适的默认构造函数(自定义交互器)

时间:2016-11-24 15:54:15

标签: c++ qt vtk

我有一个名为MainWindow的GUI,我在构造函数中渲染了一些东西。 在这个构造函数之上,我声明了一个自定义类的交互器来实现OnRightButtonDown()函数。 在这个函数中,我想从我的MainWindow类中调用一个函数。

当我运行代码时出现错误:

  

"没有合适的默认构造函数"

发生

指的是这一行:

vtkStandardNewMacro(customMouseInteractorStyle);

如何更改代码以启用带参数的构造函数?

    class customMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
    {
    public:
        static customMouseInteractorStyle* New();
        vtkTypeMacro(customMouseInteractorStyle,   vtkInteractorStyleTrackballCamera);
        MainWindow *mainWin;

        customMouseInteractorStyle(MainWindow *ptr) : mainWin(ptr)
        {

        }

        virtual void OnRightButtonDown()
        {
            mainWin->function();
            vtkInteractorStyleTrackballCamera::OnRightButtonDown();
        }
    };
    vtkStandardNewMacro(customMouseInteractorStyle);

Test1::Test1(QWidget *parent)
    : QMainWindow(parent)
{
       //Rendering
       ....
       //

    vtkSmartPointer<customMouseInteractorStyle> style =   //My custom class!!!
    vtkSmartPointer<customMouseInteractorStyle>::New();
    renderWindowInteractor->SetInteractorStyle(style);

    renderWindow->Render();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderWindowInteractor->Initialize();

}

void MainWindow::function()
{
}

1 个答案:

答案 0 :(得分:0)

 class customMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
    {
    public:
        static customMouseInteractorStyle* New();
        vtkTypeMacro(customMouseInteractorStyle,   vtkInteractorStyleTrackballCamera);
        MainWindow *mainWin;

        customMouseInteractorStyle()
        {

        }

        void  function(MainWindow *ptr)
        {
           mainWin = ptr;
        }

        virtual void OnRightButtonDown()
        {
            mainWin->function();
            vtkInteractorStyleTrackballCamera::OnRightButtonDown();
        }
    };
    vtkStandardNewMacro(customMouseInteractorStyle);

Test1::Test1(QWidget *parent)
    : QMainWindow(parent)
{
       //Rendering
       ....
       //

    vtkSmartPointer<customMouseInteractorStyle> style =   //My custom class!!!
    vtkSmartPointer<customMouseInteractorStyle>::New();
    renderWindowInteractor->SetInteractorStyle(style);
    style->function(this);

    renderWindow->Render();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderWindowInteractor->Initialize();

}

void MainWindow::function()
{
}