Results 1 to 8 of 8

Thread: #include <QApplication> undefined reference to vtable

  1. #1
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default #include <QApplication> undefined reference to vtable

    Hi all, I've just started using qt and I've run into the problem of constantly getting
    undefined reference to 'vtable for window'
    Witch is strange cause I was able to run some of the tutorial examples but this one just wont work.
    I'm using Kdevelop 3.5 on ubuntu 7.04 and using qt4
    window.h
    Qt Code:
    1. /***************************************************************************
    2.  * Copyright (C) 2007 by adriaan,,, *
    3.  * adriaan@Tornado *
    4.  * *
    5.  * This program is free software; you can redistribute it and/or modify *
    6.  * it under the terms of the GNU General Public License as published by *
    7.  * the Free Software Foundation; either version 2 of the License, or *
    8.  * (at your option) any later version. *
    9.  * *
    10.  * This program is distributed in the hope that it will be useful, *
    11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
    12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
    13.  * GNU General Public License for more details. *
    14.  * *
    15.  * You should have received a copy of the GNU General Public License *
    16.  * along with this program; if not, write to the *
    17.  * Free Software Foundation, Inc., *
    18.  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
    19.  ***************************************************************************/
    20.  
    21. #pragma once
    22.  
    23. #include <QApplication>
    24. #include <QtGui>
    25. #include <QWidget>
    26. #include <QComboBox>
    27. #include <QLineEdit>
    28. #include <QtGui>
    29. #include <QGridLayout>
    30. #include <QGroupBox>
    31. #include <QPushButton>
    32. #include <QLabel>
    33.  
    34.  
    35. class window : public QWidget
    36. {
    37.  
    38. public:
    39.  
    40. window(QWidget * parent = NULL);
    41.  
    42. ~window();
    43.  
    44. private:
    45.  
    46. QLineEdit * nameline;
    47.  
    48. QLineEdit * typeline;
    49.  
    50. QLineEdit * answerline;
    51.  
    52. };
    To copy to clipboard, switch view to plain text mode 
    window.cpp
    Qt Code:
    1. /***************************************************************************
    2.  * Copyright (C) 2007 by adriaan,,, *
    3.  * adriaan@Tornado *
    4.  * *
    5.  * This program is free software; you can redistribute it and/or modify *
    6.  * it under the terms of the GNU General Public License as published by *
    7.  * the Free Software Foundation; either version 2 of the License, or *
    8.  * (at your option) any later version. *
    9.  * *
    10.  * This program is distributed in the hope that it will be useful, *
    11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
    12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
    13.  * GNU General Public License for more details. *
    14.  * *
    15.  * You should have received a copy of the GNU General Public License *
    16.  * along with this program; if not, write to the *
    17.  * Free Software Foundation, Inc., *
    18.  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
    19.  ***************************************************************************/
    20.  
    21.  
    22. #include "window.h"
    23.  
    24. window::window(QWidget * var) : QWidget(var)
    25. {
    26.  
    27. /*=================================================
    28. * Settings *
    29. =================================================*/
    30.  
    31. setWindowTitle("Variable Definer Version 0.1");
    32.  
    33. /*=================================================
    34. * Name *
    35. =================================================*/
    36.  
    37. QGroupBox * namegroup = new QGroupBox("Name");
    38.  
    39. QLabel * namelabel = new QLabel("Enter variable name:");
    40.  
    41. nameline = new QLineEdit();
    42.  
    43. nameline->setFocus();
    44.  
    45. QGridLayout * namelayout = new QGridLayout;
    46.  
    47. namelayout->addWidget(namelabel, 0, 0);
    48.  
    49. namelayout->addWidget(nameline, 1, 0,1,2);
    50.  
    51. namegroup->setLayout(namelayout);
    52.  
    53. /*=================================================
    54. * Type *
    55. =================================================*/
    56.  
    57. QGroupBox * typegroup = new QGroupBox("Type");
    58.  
    59. QLabel * typeLabel = new QLabel("Enter variable type");
    60.  
    61. typeline = new QLineEdit();
    62.  
    63. QGridLayout * typelayout = new QGridLayout();
    64.  
    65. typelayout->addWidget(typeLabel, 0, 0);
    66.  
    67. typelayout->addWidget(typeline, 1,0,1,2);
    68.  
    69. typegroup->setLayout(typelayout);
    70.  
    71. /*=================================================
    72. * Specifiers *
    73. =================================================*/
    74.  
    75. QGroupBox * specgroup = new QGroupBox("Specifiers");
    76.  
    77. QLabel * speclabel = new QLabel("Choose the right defenition");
    78.  
    79. QPushButton * array = new QPushButton("Array (of)");
    80.  
    81. QPushButton * pointer = new QPushButton("Pointer (to)");
    82.  
    83. QPushButton * function = new QPushButton("Function");
    84.  
    85. QGridLayout * speclay = new QGridLayout();
    86.  
    87. speclay->addWidget(speclabel,0,0);
    88.  
    89. speclay->addWidget(array,1,0);
    90.  
    91. speclay->addWidget(pointer,1,1);
    92.  
    93. speclay->addWidget(function,1,2);
    94.  
    95. specgroup->setLayout(speclay);
    96.  
    97. /*=================================================
    98. * Answer *
    99. =================================================*/
    100.  
    101. QGroupBox * answergroup = new QGroupBox("Defenition");
    102.  
    103. QLabel * answerlabel = new QLabel("The correct defenition:");
    104.  
    105. answerline = new QLineEdit();
    106.  
    107. QGridLayout * anslay= new QGridLayout();
    108.  
    109. anslay->addWidget(answerlabel,0,0);
    110.  
    111. anslay->addWidget(answerline,1,0,1,2);
    112.  
    113. answergroup->setLayout(anslay);
    114.  
    115. /*=================================================
    116. * Global Layout *
    117. =================================================*/
    118.  
    119. QGridLayout * layout = new QGridLayout();
    120.  
    121. layout->addWidget(namegroup, 0, 0);
    122.  
    123. layout->addWidget(typegroup, 1, 0);
    124.  
    125. layout->addWidget(specgroup, 2, 0);
    126.  
    127. layout->addWidget(answergroup,3, 0);
    128.  
    129. setLayout(layout);
    130.  
    131. }
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. /***************************************************************************
    2.  * Copyright (C) 2007 by adriaan,,, *
    3.  * adriaan@Tornado *
    4.  * *
    5.  * This program is free software; you can redistribute it and/or modify *
    6.  * it under the terms of the GNU General Public License as published by *
    7.  * the Free Software Foundation; either version 2 of the License, or *
    8.  * (at your option) any later version. *
    9.  * *
    10.  * This program is distributed in the hope that it will be useful, *
    11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
    12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
    13.  * GNU General Public License for more details. *
    14.  * *
    15.  * You should have received a copy of the GNU General Public License *
    16.  * along with this program; if not, write to the *
    17.  * Free Software Foundation, Inc., *
    18.  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
    19.  ***************************************************************************/
    20.  
    21.  
    22. #include <QApplication>
    23.  
    24. #include "window.h"
    25.  
    26. int main(int argc, char *argv[])
    27. {
    28.  
    29. QApplication application (argc, argv);
    30.  
    31. window * newwindow = new window();
    32.  
    33. newwindow->show();
    34.  
    35. return (application.exec());
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QApplication>

    Maybe it's just a copy-paste problem but I don't see a function body for ~window().
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    sylvarant (8th September 2007)

  4. #3
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QApplication> undefined reference to vtable

    Oh damn, I did forget a destructor.
    all this trouble for something this simple
    thanx for pointing it out

  5. #4
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QApplication> undefined reference to vtable

    I' ve encountered this problem once again while trying to create a signal and slot
    and yes all functions are stated in window.cpp

    window.h
    Qt Code:
    1. /***************************************************************************
    2.  * Copyright (C) 2007 by adriaan,,, *
    3.  * adriaan@Tornado *
    4.  * *
    5.  * This program is free software; you can redistribute it and/or modify *
    6.  * it under the terms of the GNU General Public License as published by *
    7.  * the Free Software Foundation; either version 2 of the License, or *
    8.  * (at your option) any later version. *
    9.  * *
    10.  * This program is distributed in the hope that it will be useful, *
    11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
    12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
    13.  * GNU General Public License for more details. *
    14.  * *
    15.  * You should have received a copy of the GNU General Public License *
    16.  * along with this program; if not, write to the *
    17.  * Free Software Foundation, Inc., *
    18.  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
    19.  ***************************************************************************/
    20.  
    21. #pragma once
    22.  
    23. #include <QApplication>
    24. #include <QtGui>
    25. #include <QWidget>
    26. #include <QObject>
    27. #include <QComboBox>
    28. #include <QLineEdit>
    29. #include <QtGui>
    30. #include <QGridLayout>
    31. #include <QGroupBox>
    32. #include <QPushButton>
    33. #include <QLabel>
    34.  
    35.  
    36. class window : public QWidget
    37. {
    38.  
    39. Q_OBJECT
    40.  
    41. public:
    42.  
    43. window(QWidget * parent = NULL);
    44.  
    45. ~window();
    46.  
    47.  
    48. public slots:
    49.  
    50. void select(int choice);
    51.  
    52.  
    53. signals:
    54.  
    55. void createanswer(int al);
    56.  
    57.  
    58. private:
    59.  
    60. QLineEdit * nameline;
    61.  
    62. QLineEdit * typeline;
    63.  
    64. QLineEdit * answerline;
    65.  
    66. };
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: #include <QApplication> undefined reference to vtable

    Make sure window.h is listed in .pro file and then try re-running qmake. In general, you should always re-run qmake after adding Q_OBJECT macro so that required make rules for moc get generated.
    J-P Nurmi

  7. #6
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: #include <QApplication> undefined reference to vtable

    It seems to be in there but no moc files are created when compiling and thats probably the problem but I have no idea of how to fix this.
    It's probably something Kdevelop related.

  8. #7
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: #include <QApplication>

    if no moc files are created then, run a qmake. ( just a jpn had mentioned )
    We can't solve problems by using the same kind of thinking we used when we created them

  9. #8
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: #include <QApplication> undefined reference to vtable

    You need to rebuild your app from scratch.
    I mean, recompile, not delete your work and start over

    just run:
    make distclean
    qmake
    make

Similar Threads

  1. please help with linker errors
    By jimboqt in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2007, 10:49
  2. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 15:28
  3. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 20:15
  4. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 20:36
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2006, 00:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.