Results 1 to 6 of 6

Thread: Signals from inherited widgets

  1. #1
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    10

    Default Signals from inherited widgets

    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.

    Qt Code:
    1. class MyTableView : public QTableView{
    2. ...
    3. signals:
    4. void mySignal(int);
    5. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. MyTableView *myTableView=new MyTableView();
    2. connect(myTableView, SIGNAL(mySignal(int)), ...
    To copy to clipboard, switch view to plain text mode 

    At run time, I have the error message:

    Qt Code:
    1. Object::connect: No such signal QTableView::mySignal(int)
    To copy to clipboard, switch view to plain text mode 

    Thank you!

  2. #2
    Join Date
    Feb 2010
    Location
    Hyderabad, India
    Posts
    15
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signals from inherited widgets

    Did you use the macro Q_OBJECT in the class declaration ?

    Qt Code:
    1. class MyTableView : public QTableView{
    2. Q_OBJECT
    3. ...
    4. signals:
    5. void mySignal(int);
    6. };
    To copy to clipboard, switch view to plain text mode 

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

    pippo42 (25th February 2010)

  4. #3
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    10

    Default Re: Signals from inherited widgets

    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?).

  5. #4
    Join Date
    Feb 2010
    Location
    Hyderabad, India
    Posts
    15
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signals from inherited widgets

    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/2840...ghlight=vtable

  6. The following user says thank you to mrvk for this useful post:

    pippo42 (25th February 2010)

  7. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Signals from inherited widgets

    u need to include Q_OBJECT macro

    as mrvk mentioned
    http://www.qtcentre.org/threads/2840...ghlight=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
    Last edited by BalaQT; 25th February 2010 at 09:26.

  8. The following user says thank you to BalaQT for this useful post:

    pippo42 (25th February 2010)

  9. #6
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    10

    Default Re: Signals from inherited widgets

    Thank you very much to all of you!

    Problem solved!

Similar Threads

  1. Inherited Style Sheet
    By johnmauer in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2010, 21:07
  2. Dynamic widgets adding and connecting signals& slots
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 22nd May 2009, 12:36
  3. How QMessageBox can be inherited.
    By rajveer in forum Qt Programming
    Replies: 40
    Last Post: 10th September 2008, 14:27
  4. Replies: 2
    Last Post: 16th May 2008, 14:39
  5. Mess with inherited constructors
    By Pepe in forum Newbie
    Replies: 8
    Last Post: 8th September 2007, 17:16

Tags for this Thread

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.