PDA

View Full Version : Signals from inherited widgets



pippo42
25th February 2010, 08:11
Hello,

I have created a class that inherits from QTableView and given it a signal. When I try to connect to it, I have an error message, at run time, that says that QTableView has no such signal but the object I am using is an instance of the class I have inherited from QTableView.

What I am doing wrong?

Here a sample of code that will make things clearer.



class MyTableView : public QTableView{
...
signals:
void mySignal(int);
};



MyTableView *myTableView=new MyTableView();
connect(myTableView, SIGNAL(mySignal(int)), ...


At run time, I have the error message:



Object::connect: No such signal QTableView::mySignal(int)


Thank you!

mrvk
25th February 2010, 08:29
Did you use the macro Q_OBJECT in the class declaration ?



class MyTableView : public QTableView{
Q_OBJECT
...
signals:
void mySignal(int);
};

pippo42
25th February 2010, 08:46
Thank you for your reply.

I have tried with and without the Q_OBJECT macro.

When I include Q_OBJECT in the class declaration, I have error messages saying "undefined reference to vtable for MyTableView". But all the functions are defined. It happens also if I define the signal (but I am not supposed to do this?).

mrvk
25th February 2010, 09:10
If you need to use signals and slots, then you need to use the macro, Q_OBJECT.

Regarding your error, just take a look at this thread. Hope it helps.

http://www.qtcentre.org/threads/28401-Qt-Undefined-Reference-to-vtable?highlight=vtable

BalaQT
25th February 2010, 09:14
u need to include Q_OBJECT macro

as mrvk mentioned
http://www.qtcentre.org/threads/28401-Qt-Undefined-Reference-to-vtable?highlight=vtable
this thread holds the following ans


Re: Qt Undefined Reference to vtable

Typically, if you get "Undefined Reference to vtable" whilst building a project you need to ensure MOC is being run. The easiest way to ensure this is to simply run qmake from the QtCreator menu bar and then rebuild the project. Q_OBJECT is only required if your class needs signals or slots - these are then read by MOC and parsed into another file that it creates and automatically adds to your project. Without this file, you get the vtable error.



Bala

pippo42
25th February 2010, 09:47
Thank you very much to all of you!

Problem solved!