Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why I'm getting error on undefinded reference on object slot
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thippu
    wrote on last edited by thippu
    #1

    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?

    J.HilkJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      3
      • T thippu

        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?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

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


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        T 1 Reply Last reply
        4
        • J.HilkJ J.Hilk

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

          T Offline
          T Offline
          thippu
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            super
            So was it a missing body ?

            T 1 Reply Last reply
            0
            • mrjjM mrjj

              super
              So was it a missing body ?

              T Offline
              T Offline
              thippu
              wrote on last edited by
              #6

              @mrjj Yes

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved