PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Probleme beim Kompilieren mit QT (Anfänger) -> undefined reference to `vtable ...



Morfio
17-01-2005, 17:43
Hi,

ich wollte mich mal was mit QT und C++ beschäftigen, hänge aber schon eine ganze Weile an einem Problem. Ich habe mit "designer" eine kleine grafische Oberfläche entworfen (naja, eher nur eine Form), die von QMainWindow abgeleitet ist. Ich möchte von der Klasse nun ein Objekt erstellen und einfach das Fenster anzeigen. Hier die 3 Dateien:

dsadmin.cpp (hier soll das Fenster einfach aufgerufen werden):


#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>

#include "ds.h"

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

QApplication a( argc, argv );
myForm1 * myform = new myForm1();
myform->show();
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
return a.exec();

}

ds.h:


#include <qvariant.h>
#include <qmainwindow.h>

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QAction;
class QActionGroup;
class QToolBar;
class QPopupMenu;

class myForm1 : public QMainWindow
{
Q_OBJECT

public:
myForm1( QWidget* parent = 0, const char* name = 0, WFlags fl = WType_TopLevel );
~myForm1();


protected:

protected slots:
virtual void languageChange();

};

und ds.cpp:


#include "ds.h"

#include <qvariant.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qaction.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qtoolbar.h>

/*
* Constructs a Form1 as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
*/
myForm1::myForm1( QWidget* parent, const char* name, WFlags fl )
: QMainWindow( parent, name, fl )
{
(void)statusBar();
if ( !name )
setName( "Form1" );

// toolbars

languageChange();
resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );
}

/*
* Destroys the object and frees any allocated resources
*/
myForm1::~myForm1()
{
// no need to delete child widgets, Qt does it all for us
}

/*
* Sets the strings of the subwidgets using the current
* language.
*/
void myForm1::languageChange()
{
setCaption( tr( "Form1" ) );
}

Die Klasse (myForm1) und deren Implementation habe ich mit uic erstellt.

Wenn ich das nun kompiliere (qmake -o Makefile src.pro; make), kommen die folgenden Fehler:


[18:36:20 thorsten@bart src]: make
test -d ../bin/ || mkdir -p ../bin/
g++ -Wl,-rpath,/usr/qt/3/lib -o ../bin/dsadmin dsadmin.o ds.o -L/usr/qt/3/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm
ds.o(.text+0x2e): In function `myForm1::myForm1[not-in-charge](QWidget*, char const*, unsigned)':
: undefined reference to `vtable for myForm1'
ds.o(.text+0x35): In function `myForm1::myForm1[not-in-charge](QWidget*, char const*, unsigned)':
: undefined reference to `vtable for myForm1'
ds.o(.text+0x11e): In function `myForm1::myForm1[in-charge](QWidget*, char const*, unsigned)':
: undefined reference to `vtable for myForm1'
ds.o(.text+0x125): In function `myForm1::myForm1[in-charge](QWidget*, char const*, unsigned)':
: undefined reference to `vtable for myForm1'
ds.o(.text+0x1eb): In function `myForm1::~myForm1 [not-in-charge]()':
: undefined reference to `vtable for myForm1'
ds.o(.text+0x1f2): more undefined references to `vtable for myForm1' follow
ds.o(.text+0x276): In function `myForm1::languageChange()':
: undefined reference to `myForm1::tr(char const*, char const*)'
collect2: ld returned 1 exit status
make: *** [../bin/dsadmin] Error 1

Da ist bestimmt nur ein ganz kleiner, dummer Fehler. Aber wie so oft: man selbst sieht oft den Wald vor lauter Bäumen nicht.

Vllt. weiss jemand von Euch, wo ich da nachbessern kann.

Vielen Dank,

Morfio ...

peschmae
17-01-2005, 17:50
Bei mir geht das Programm.

Ich hatte auch schon so Probleme. Mach mal ein "make clean" (und eventuell auch das qmake-File neu machen, qmake -project; qmake; make) das hat bei mir afair jeweils geholfen.

Oder sind eine QTDIR- und ähnliche Einstellungen nicht in Ordnung?

MfG Peschmä

Morfio
17-01-2005, 17:56
Super, es funktioniert. Vielen Dank.