我有两个函数,其中一个调用另一个。我想将它们中的一个作为插槽来使用,连接到PushButton的clicked()信号上。以下是我的planevolume.h代码的部分内容,以便您理解:
#ifndef PLANEVOLUME_H
#define PLANEVOLUME_H
#include <QMainWindow>
namespace Ui {
class planevolume;
}
//more stuff here
class planevolume : public QMainWindow {
Q_OBJECT
public:
planevolume(QWidget *parent = 0);
~planevolume();
protected:
void changeEvent(QEvent *e);
private:
Ui::planevolume *ui;
//more stuff here
public slots:
void AlignXAxis(int xmin, int xmax, vtkImagePlaneWidget* planeX);
void AlignCamera(vtkImagePlaneWidget* current_widget);
};
#endif // PLANEVOLUME_H
我会放在这里一些我的planevolume.cpp代码,这样你就可以理解我遇到的错误了。
#include <qwidget.h>
#include <qaction.h>
#include <qobject.h>
//more includes
// Define AlignCamera
void planevolume::AlignCamera(vtkImagePlaneWidget* current_widget)
{
//regular statements of a function
vtkCamera *camera=ren->GetActiveCamera();
camera->SetViewUp(vx, vy, vz);
camera->SetFocalPoint(cx, cy, cz);
camera->SetPosition(px, py, pz);
camera->OrthogonalizeViewUp();
ren->ResetCameraClippingRange();
renWin->Render();
}
// Define the action of AlignXAxis
void planevolume::AlignXAxis(int xmin, int xmax, vtkImagePlaneWidget* planeX)
{
//regular statements of a function
vtkImagePlaneWidget *current_widget= planeX;
ui->horizontalScrollBar->setValue(slice_number);
ui->horizontalScrollBar->setMinimum(xmin);
ui->horizontalScrollBar->setMaximum(xmax);
AlignCamera(current_widget);//here I call the other one
}
planevolume::planevolume(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::planevolume)
{
ui->setupUi(this);
//regular stuff
//I think here is the problem when i make the connect
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(AlignXAxis(int, int, vtkImagePlaneWidget)));
// Start the initialization and rendering
renWin->Render();
//iren->Initialize();
//iren->Start();
// Assign the rendering window to the qvtkwidget
ui->qvtkWidget->SetRenderWindow(renWin);
}
当我编译它时,好像一切都没有问题,但是当我点击PushButton时,应用程序的输出窗口只显示如下内容:
Object::connect: 在planevolume.cpp文件的第386行中没有名为planevolume :: AlignXAxis(int,int,vtkImagePlaneWidget)的槽。 Object::connect: (发送者名称:“pushButton”) Object::connect: (接收者名称:“planevolume”)
如果有人知道我做错了什么,请给我一些提示或建议,因为这让我感到非常疯狂。 :)
ui->lineEditxMin->value()
。 - Tim MeyerQ_OBJECT
类,如何从pushButton
的clicked()
事件触发它的事件? - Junaid Qadir Shekhanzai