Why I'm getting error on undefinded reference on object slot



  • hi,
    I have a plot class object in mainwindow class
    In mainwindow class, I did connect plot class object and whenever mainwindow object's button is clicked,
    Syntax is fine,I think
    But why I'm getting error?

    here plot header file:

    class Plot: public QwtPlot
    {
        Q_OBJECT
    
       public:
        Plot( QWidget * = NULL );
        virtual ~Plot();
    
        void start();
        virtual void replot();
    
        virtual bool eventFilter( QObject *, QEvent * );
    
    public Q_SLOTS:
        void setIntervalLength( double );
        void setCh1();
    
    

    And
    mainwindow cpp:

    
    MainWindow::MainWindow( QWidget *parent ):
        QWidget( parent )
    {
        const double intervalLength = 1.0; // refered in seconds,used to sets the x scale and also Display widget to intervalLength
    
        d_plot = new Plot( this );
        d_plot->setIntervalLength( intervalLength );//sets the x scale by intervalLength
    
        d_amplitudeKnob = new Knob( "Amplitude", 0.0, 200.0, this );
        d_amplitudeKnob->setValue( 50.0 );
    
        d_frequencyKnob = new Knob( "Frequency [Hz]", 0.1, 20.0, this );
        d_frequencyKnob->setValue( 2.5 );
    
        d_intervalWheel = new WheelBox( "Displayed [s]", 1.0, 100.0, 1.0, this );//display wheel
        d_intervalWheel->setValue( intervalLength );
    
        d_timerWheel = new WheelBox( "Sample Interval [ms]", 0.0, 20.0, 0.1, this );//sample wheel
        d_timerWheel->setValue( 10.0 );
    
    
        ch1=new QPushButton("Turn on ch1",this);
        ch2=new QPushButton("Turn on ch2",this);
        ch3=new QPushButton("Turn on ch3",this);
        ch4=new QPushButton("Turn on ch4",this);
    
        QVBoxLayout *hchannelLayout=new QVBoxLayout();
        hchannelLayout->addWidget(ch1);
        hchannelLayout->addWidget(ch2);
        hchannelLayout->addWidget(ch3);
        hchannelLayout->addWidget(ch4);
    
        QVBoxLayout* vLayout1 = new QVBoxLayout();
        vLayout1->addWidget( d_intervalWheel );
        vLayout1->addWidget( d_timerWheel );
        vLayout1->addStretch( 5 );
        vLayout1->addLayout(hchannelLayout);
        vLayout1->addWidget( d_amplitudeKnob );
        vLayout1->addWidget( d_frequencyKnob );
    
    
        QHBoxLayout *layout = new QHBoxLayout( this );
        layout->addWidget( d_plot, 10 );
        layout->addLayout( vLayout1 );
    
    
        connect( d_amplitudeKnob, SIGNAL( valueChanged( double ) ),
            SIGNAL( amplitudeChanged( double ) ) );
        connect( d_frequencyKnob, SIGNAL( valueChanged( double ) ),
            SIGNAL( frequencyChanged( double ) ) );
        connect( d_timerWheel, SIGNAL( valueChanged( double ) ),
            SIGNAL( signalIntervalChanged( double ) ) );
    
        connect( d_intervalWheel, SIGNAL( valueChanged( double ) ),
            d_plot, SLOT( setIntervalLength( double ) ) );
    
    
        connect(ch1,SIGNAL(clicked()),
                d_plot,SLOT(setCh1()));
    }
    
    

    error:
    build-oscilloscope-Desktop_Qt_5_9_0_MinGW_32bit-Debug/moc/moc_plot.cpp:75: undefined reference to `Plot::setCh1()'
    collect2.exe: error: ld returned 1 exit status

    So, What to do?


  • Qt Champions 2017

    Hi
    Completely delete build folder.
    and see.
    seems ok.



  • @thippu
    also make sure, your setCh1 function has a body in your plot.cpp file.



  • @J.Hilk @mrjj Thank you,those were the mistake
    Now it is building the project.
    :) thank you guys


  • Qt Champions 2017

    super
    So was it a missing body ?



  • @mrjj Yes


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.