Hi there--I'm just now learning Qt, and am trying to get a basic signals program working. It compiles, but links unsuccessfully (the compiler complains about the virtual table). I built the program with the standard qmake -project, qmake, make instructions. Does anyone have any ideas on this?
Here's the code, followed by the compiler output:
#include <QtCore/QObject>
#include <iostream>
{
Q_OBJECT
public:
Go() { ; }
~Go() { ; }
void go()
{
std::cout << "Emitting signal..." << std::endl;
emit emit_signal();
}
public slots:
void receive_signal()
{
std::cout << "Received signal!" << std::endl;
}
signals:
void emit_signal() { }
};
int main()
{
Go g1, g2;
QObject::connect(&g1,
SIGNAL (emit_signal
()),
&g2, SLOT (receive_signal ()));
g1.go();
return 0;
}
#include <QtCore/QObject>
#include <iostream>
class Go : public QObject
{
Q_OBJECT
public:
Go() { ; }
~Go() { ; }
void go()
{
std::cout << "Emitting signal..." << std::endl;
emit emit_signal();
}
public slots:
void receive_signal()
{
std::cout << "Received signal!" << std::endl;
}
signals:
void emit_signal() { }
};
int main()
{
Go g1, g2;
QObject::connect(&g1, SIGNAL (emit_signal ()),
&g2, SLOT (receive_signal ()));
g1.go();
return 0;
}
To copy to clipboard, switch view to plain text mode
[Compiler output]
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/qt/mkspecs/linux-g++ -I. -I/usr/local/qt42/include/QtCore -I/usr/local/qt42/include/QtCore -I/usr/local/qt42/include/QtGui -I/usr/local/qt42/include/QtGui -I/usr/local/qt42/include -I. -I. -I. -o qtest.o qtest.C
g++ -o qtest qtest.o -L/usr/local/qt42/lib -lQtGui -L/usr/local/qt/lib -L/usr/X11R6/lib -lpng -lSM -lICE -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -lglib-2.0 -ldl -lpthread
qtest.o(.text+0x24): In function `main':
: undefined reference to `vtable for Go'
qtest.o(.text+0x43): In function `main':
: undefined reference to `vtable for Go'
qtest.o(.text+0x6a): In function `main':
: undefined reference to `vtable for Go'
qtest.o(.text+0x7c): In function `main':
: undefined reference to `vtable for Go'
qtest.o(.text+0x9d): In function `main':
: undefined reference to `vtable for Go'
qtest.o(.text+0xb0): more undefined references to `vtable for Go' follow
collect2: ld returned 1 exit status
make: *** [qtest] Error 1
Thanks!
--Steve (sgross@sjm.com)
Bookmarks