c++ - compile a Qt single file from command line: undefined reference to vtable -


i'd compile single file qt application command line, test in quick way features. see code of file below.

i'm compiling with:

qmake -project && qmake && make 

and i' getting error:

togglebutton.o:togglebutton.cpp:function buttondialog::buttondialog(qwidget*): error: undefined reference 'vtable buttondialog' togglebutton.o:togglebutton.cpp:function buttondialog::buttondialog(qwidget*): error: undefined reference 'vtable buttondialog' togglebutton.o:togglebutton.cpp:function buttondialog::~buttondialog(): error: undefined reference 'vtable buttondialog' togglebutton.o:togglebutton.cpp:function buttondialog::~buttondialog(): error: undefined reference 'vtable buttondialog' 

i'm not c++ guru, i've tried google undefined reference vtable don't understad why i'm getting error 1 file..

someone can me in understaning undefined vtable error?

/*  * copyright (c) 2006-2007, johan thelin  *   * rights reserved.  *   * redistribution , use in source , binary forms, or without modification,   * permitted provided following conditions met:  *   *     * redistributions of source code must retain above copyright notice,   *       list of conditions , following disclaimer.  *     * redistributions in binary form must reproduce above copyright notice,    *       list of conditions , following disclaimer in documentation   *       and/or other materials provided distribution.  *     * neither name of apress nor names of contributors   *       may used endorse or promote products derived software   *       without specific prior written permission.  *   * software provided copyright holders , contributors  * "as is" , express or implied warranties, including, not  * limited to, implied warranties of merchantability , fitness  * particular purpose disclaimed. in no event shall copyright owner or  * contributors liable direct, indirect, incidental, special,  * exemplary, or consequential damages (including, not limited to,  * procurement of substitute goods or services; loss of use, data, or  * profits; or business interruption) caused , on theory of  * liability, whether in contract, strict liability, or tort (including  * negligence or otherwise) arising in way out of use of  * software, if advised of possibility of such damage.  *  */  #include <qpushbutton> #include <qhboxlayout> #include <qmessagebox>  #include <qapplication> #include <qdialog> class qpushbutton;  class buttondialog : public qdialog {   q_object  public:   buttondialog( qwidget *parent=0 );  private slots:   void buttonclicked();   void buttontoggled();  private:   qpushbutton *clickbutton;   qpushbutton *togglebutton; };  buttondialog::buttondialog( qwidget *parent ) : qdialog( parent ) {   clickbutton = new qpushbutton( "click me!", );   togglebutton = new qpushbutton( "toggle me!", );   togglebutton->setcheckable( true );    qhboxlayout *layout = new qhboxlayout( );   layout->addwidget( clickbutton );   layout->addwidget( togglebutton );    connect( clickbutton, signal(clicked()), this, slot(buttonclicked()) );   connect( togglebutton, signal(clicked()), this, slot(buttontoggled()) ); }  void buttondialog::buttonclicked() {   qmessagebox::information( this, "clicked!", "the button clicked!" ); }  void buttondialog::buttontoggled() {   qmessagebox::information( this, "toggled!", qstring("the button %1!").arg(togglebutton->ischecked()?"pressed":"released") ); }   int main( int argc, char **argv ) {   qapplication app( argc, argv );    buttondialog dlg;   dlg.show();    return app.exec(); } 

i had same mistake, when declared q_object class in cpp file. create header , move class declaration there.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -