Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Out-of-line definition of --constructor-- does not match any declaration in --class--



  • I have this header file (graphics_view_zoom.h):

    #include <QObject>
    #include <view.h>
    
    class Graphics_view_zoom : public QObject {
      Q_OBJECT
    public:
      Graphics_view_zoom(View* view);
      // stuff
    
    private:
      View* _view;
      // other stuff
    
    };
    

    And this cpp file (graphics_view_zoom.cpp):

    #include "Graphics_view_zoom.h"
    #include <view.h>
    
    Graphics_view_zoom::Graphics_view_zoom(View* view) // error: out-of-line definition of 'Graphics_view_zoom' does not match any declaration in 'Graphics_view_zoom'
      : QObject(view), _view(view)
    {
       // more stuff
    }
    

    Why does this happen? It works fine when I use QGraphicsView* instead of View* (my custom class View inherits from QGraphicsView). Any help is appreciated!


  • Lifetime Qt Champion

    Hi,

    In your declaration you pass an instance and in the implementation you pass a pointer.



  • @Forfunckle

    Is your custom View class a QObject? Otherwise your call of the QObject() c'tor with view as argument won't work.


Log in to reply