PDA

View Full Version : #include <QApplication> undefined reference to vtable



sylvarant
8th September 2007, 22:08
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


/************************************************** *************************
* Copyright (C) 2007 by adriaan,,, *
* adriaan@Tornado *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************** *************************/

#pragma once

#include <QApplication>
#include <QtGui>
#include <QWidget>
#include <QComboBox>
#include <QLineEdit>
#include <QtGui>
#include <QGridLayout>
#include <QGroupBox>
#include <QPushButton>
#include <QLabel>


class window : public QWidget
{

public:

window(QWidget * parent = NULL);

~window();

private:

QLineEdit * nameline;

QLineEdit * typeline;

QLineEdit * answerline;

};

window.cpp

/************************************************** *************************
* Copyright (C) 2007 by adriaan,,, *
* adriaan@Tornado *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************** *************************/


#include "window.h"

window::window(QWidget * var) : QWidget(var)
{

/*=================================================
* Settings *
=================================================*/

setWindowTitle("Variable Definer Version 0.1");

/*=================================================
* Name *
=================================================*/

QGroupBox * namegroup = new QGroupBox("Name");

QLabel * namelabel = new QLabel("Enter variable name:");

nameline = new QLineEdit();

nameline->setFocus();

QGridLayout * namelayout = new QGridLayout;

namelayout->addWidget(namelabel, 0, 0);

namelayout->addWidget(nameline, 1, 0,1,2);

namegroup->setLayout(namelayout);

/*=================================================
* Type *
=================================================*/

QGroupBox * typegroup = new QGroupBox("Type");

QLabel * typeLabel = new QLabel("Enter variable type");

typeline = new QLineEdit();

QGridLayout * typelayout = new QGridLayout();

typelayout->addWidget(typeLabel, 0, 0);

typelayout->addWidget(typeline, 1,0,1,2);

typegroup->setLayout(typelayout);

/*=================================================
* Specifiers *
=================================================*/

QGroupBox * specgroup = new QGroupBox("Specifiers");

QLabel * speclabel = new QLabel("Choose the right defenition");

QPushButton * array = new QPushButton("Array (of)");

QPushButton * pointer = new QPushButton("Pointer (to)");

QPushButton * function = new QPushButton("Function");

QGridLayout * speclay = new QGridLayout();

speclay->addWidget(speclabel,0,0);

speclay->addWidget(array,1,0);

speclay->addWidget(pointer,1,1);

speclay->addWidget(function,1,2);

specgroup->setLayout(speclay);

/*=================================================
* Answer *
=================================================*/

QGroupBox * answergroup = new QGroupBox("Defenition");

QLabel * answerlabel = new QLabel("The correct defenition:");

answerline = new QLineEdit();

QGridLayout * anslay= new QGridLayout();

anslay->addWidget(answerlabel,0,0);

anslay->addWidget(answerline,1,0,1,2);

answergroup->setLayout(anslay);

/*=================================================
* Global Layout *
=================================================*/

QGridLayout * layout = new QGridLayout();

layout->addWidget(namegroup, 0, 0);

layout->addWidget(typegroup, 1, 0);

layout->addWidget(specgroup, 2, 0);

layout->addWidget(answergroup,3, 0);

setLayout(layout);

}


main.cpp

/************************************************** *************************
* Copyright (C) 2007 by adriaan,,, *
* adriaan@Tornado *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************** *************************/


#include <QApplication>

#include "window.h"

int main(int argc, char *argv[])
{

QApplication application (argc, argv);

window * newwindow = new window();

newwindow->show();

return (application.exec());

}

jpn
8th September 2007, 22:13
Maybe it's just a copy-paste problem but I don't see a function body for ~window(). ;)

sylvarant
8th September 2007, 22:15
Oh damn, I did forget a destructor.
all this trouble for something this simple :p
thanx for pointing it out

sylvarant
9th September 2007, 11:01
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

/************************************************** *************************
* Copyright (C) 2007 by adriaan,,, *
* adriaan@Tornado *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************** *************************/

#pragma once

#include <QApplication>
#include <QtGui>
#include <QWidget>
#include <QObject>
#include <QComboBox>
#include <QLineEdit>
#include <QtGui>
#include <QGridLayout>
#include <QGroupBox>
#include <QPushButton>
#include <QLabel>


class window : public QWidget
{

Q_OBJECT

public:

window(QWidget * parent = NULL);

~window();


public slots:

void select(int choice);


signals:

void createanswer(int al);


private:

QLineEdit * nameline;

QLineEdit * typeline;

QLineEdit * answerline;

};

jpn
9th September 2007, 11:18
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.

sylvarant
9th September 2007, 21:53
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.

sunil.thaha
10th September 2007, 14:14
if no moc files are created then, run a qmake. ( just a jpn had mentioned )

Tux-Slack
10th September 2007, 19:35
You need to rebuild your app from scratch.
I mean, recompile, not delete your work and start over :)

just run:
make distclean
qmake
make