-2

I have a Qt application with visualisation of a VTK data now what i want to do is to capture the point from thr VTK data (3 coordinates) and then launch a function from the MainWindow class (MainWindow::slotLeftButtonPressEvent).

So i have a MainWindow class and another Class MainController wich has a 3 signals (one of them is "sigPointIsPicked" when the point has been selected )

so what i did is

connect(mController, SIGNAL(sigPointIsPicked()), this, SLOT(slotLeftButtonPressEvent()));

where mController is an instance of MainController class.

it seems ok to compile but when run the app and i click left button of the mouse nothing happens QT version 5.4 MainController.h

class MainController : public QObject
{
    Q_OBJECT
    public:
        MainController(StructureSensor * camera);
        virtual ~MainController();
        void start();
        void stop();
        vtkSmartPointer<vtkPoints> getClusteredPoints();
        vtkSmartPointer < vtkPolyData >  getPosedObject();
        void setPickedPoint(double &x, double &y, double &z);

    signals:
        void sigClusteringOK();
        void sigClusteringKO();
        void sigPointIsPicked();
    
    private slots:
        void slotConnectCamera();
        void slotCluster();
    
        
    private : 
        QStateMachine mStateMachine;
        std::shared_ptr<QState> mPickingState;
        std::shared_ptr<QState> mVisualisationState;
        std::shared_ptr<QState> mFinalState;
        std::shared_ptr<QState> mClusteringState;
        std::shared_ptr<QState> mVisualizationState;
        StructureSensor * mCamera;
        PointCloudClusterAlgorithm mCluster;
};

MainWindow.h

class MainWindow : public QWidget
{
    Q_OBJECT
    public:
        MainWindow(MainController * controller, StructureSensor * camera, QWidget * parent = nullptr);
        virtual ~MainWindow();

    protected:
        void closeEvent(QCloseEvent *event);
        void Spherefit();
        
    private slots:
        void displayPointCloud();
        void quit();
        void Process_Frame_Button_clicked();
        void slotLeftButtonPressEvent(vtkObject *, unsigned long, void *, void *, vtkCommand *command);
        
    private:
        MainController * mController;
        StructureSensor * mCamera;
        Ui::MainWindow mUi; //!< GUI of the view 
        vtkSmartPointer< vtkRenderer >  mRenderer;
        vtkSmartPointer< vtkActor > mPointCloudActor;
        vtkSmartPointer< vtkVertexGlyphFilter > mVertexGlyphFilter;
        vtkSmartPointer< vtkPolyData > mPointCloudPolyData;
        pcl::PointCloud<pcl::PointXYZ>::Ptr mCloudPCL;
        pcl::ModelCoefficients::Ptr  mSphereCoefficients;
};
General Grievance
  • 4,555
  • 31
  • 31
  • 45
BobbyMontana
  • 49
  • 1
  • 4
  • First: which version of Qt is in use? Background of this question: If you are using a version > 5.5 you can use function pointers insted of SIGNAL() SLOT() macros. Second hint: have you check the debug log of Qt if there are any errors like: Cannont connect signal slot? – KimKulling May 10 '16 at 12:13
  • I am using QT version 5.4 (and VTK version 6.30) I have just noticed on the console app this message: QObject::connect: Incompatible sender/receiver arguments – BobbyMontana May 10 '16 at 12:20
  • Please provide a more information. http://stackoverflow.com/help/mcve Namely, at least your Maincontroller class declaration and signal declaration. Plus the class declaration containing the slot and the slot declaration – Tezirg May 10 '16 at 12:32
  • Make sure that all arguments of your signal are fititing into your selected slot. The log-message indicates that there is a mismatch between them. Maybe you could show the signatures of your classes? – KimKulling May 10 '16 at 12:42
  • 1
    Don't delete/empty your post please, your issue could be interesting and read by others vtk developers – Marcassin May 25 '16 at 11:09

3 Answers3

2

You just answered your own question. Your slot expects an argument type that cannot be converted from the signal's type.

class Foo
    ...
    void mySlot(QPoint p);
    void mySlot2(int i);
    void mySlot3();
    void mySlot4(QVariant v);
    void mySlot5(QVariant v, int i);

... //elsewhere
class Bar
    ...
    void mySignal(int);
...
//And the connections:
Foo foo;
Bar bar;
connect(&bar, SIGNAL(mySignal(int)), &foo, SLOT(mySlot(QPoint))); //won't work
connect(&bar, SIGNAL(mySignal(int)), &foo, SLOT(mySlot2(int))); //works; matching argument types
connect(&bar, SIGNAL(mySignal(int)), &foo, SLOT(mySlot3())); //works; drops the int argument
connect(&bar, SIGNAL(mySignal(int)), &foo, SLOT(mySlot4(QVariant))); //works; implicit conversion
connect(&bar, SIGNAL(mySignal(int)), &foo, SLOT(mySlot5(QVariant, int))); //nope; more expected arguments than the signal provides

Edit: Your code matches the expectations above. The slot you've connected to takes multiple arguments, while the signal provides none.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42
1

If you want to have a compile-time-check for your signal-slot-connection you can use the new syntax which is descriped here: New Signal-Slot-Syntax in Qt5.

The old version which is used in your code is based on string-comparison ( this is what the macros SIGNAL and SLOT are doing ). The new syntax is based on function pointers. If the arguments are not fitting you will get a compile-time-error and the overall-performance of the code should be better.

KimKulling
  • 2,654
  • 1
  • 15
  • 26
0

As pointed out by Jon Harper, you have arguments mismatch between your signal and slot.

Your signal should look like this

 void sigPointIsPicked(vtkObject *, unsigned long, void *, void *, vtkCommand *);

And you should emit like this :

 emit sigPointIsPicked(vtkObj_ptr, ulong_value, void_ptr_one, void_ptr_two, vtkCmd_ptr);
Tezirg
  • 1,629
  • 1
  • 10
  • 20