Results 1 to 19 of 19

Thread: Qt Undefined Reference to vtable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Undefined Reference to vtable

    commented it out and i still get the same error

  2. #2
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Undefined Reference to vtable

    Post the last version of the code of jaus.h and jaus.cpp
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  3. #3
    Join Date
    Apr 2009
    Posts
    36
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Undefined Reference to vtable

    It may be useful to post updated code with a note of what changed and the specific errors you are getting.

  4. #4
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Undefined Reference to vtable

    Here's my updated code:
    Qt Code:
    1. #ifndef JAUS_H
    2. #define JAUS_H
    3.  
    4. #include <QtNetwork>
    5. #include <QUdpSocket>
    6. #include <QObject>
    7.  
    8. struct Jaus_header
    9. {
    10. unsigned short message_properties;
    11. unsigned short command_code;
    12. QByteArray dest_id[4];
    13. QByteArray source_id[4];
    14. unsigned short data_control;
    15. unsigned short sequence_num;
    16. };
    17.  
    18. class Jaus_neighbor : public QObject
    19. {
    20. Q_OBJECT
    21.  
    22. public:
    23. void handshake();
    24. void capabilities_discover();
    25. void sys_management();
    26. void close_conn();
    27.  
    28. private:
    29. Jaus_header head;
    30.  
    31. QUdpSocket *udpSocket;
    32.  
    33. private slots:
    34. Jaus_neighbor();
    35.  
    36. void prepare_header();
    37. void read_jheader();
    38. void send_jheader();
    39.  
    40. void do_command();
    41. void startBroadcasting();
    42. void stopBroadcasting();
    43. void sendDatagram();
    44. //void verifyDatagram();
    45. };
    46.  
    47. #endif // JAUS_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "jaus.h"
    2.  
    3. Jaus_neighbor::Jaus_neighbor()
    4. {
    5. udpSocket = new QUdpSocket(this);
    6. for (int i = 0; i < 4; i++)
    7. {
    8. head.dest_id[i] = 0;
    9. head.source_id[i] = 0;
    10. }
    11. head.sequence_num = 0;
    12. head.data_control = 0;
    13. head.message_properties = 0;
    14. head.command_code = 0;
    15. }
    16.  
    17. void Jaus_neighbor::startBroadcasting()
    18. {
    19.  
    20. }
    21.  
    22. void Jaus_neighbor::stopBroadcasting()
    23. {
    24.  
    25. }
    26.  
    27. void Jaus_neighbor::sendDatagram()
    28. {
    29. //udpSocket->writeDatagram(message, QHostAddress::LocalHost, 9000);
    30. }
    31.  
    32.  
    33. void Jaus_neighbor::handshake()
    34. {
    35. Jaus_neighbor::startBroadcasting();
    36. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <iostream>
    3. #include "jaus.h"
    4. using namespace std;
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9.  
    10. cout << "Initializing Jaus Connections..." << flush;
    11. //Jaus_neighbor cop;
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    I'm still getting the warnings -- but more importantly I think, is I'm getting the following error also: error: collect2: ld returned 1 exit status
    If I comment out my default constructor, the app compiles fine.

  5. #5
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Undefined Reference to vtable

    You have your constructor in private slots, that means when you declare an Jaus_neighbor object you can't access the constructor cause it's private. So move it to public.
    Also you're getting undefined references for the functions prepare_header(), read_jheader(), send_jheader() and do_command() because there aren't implementation for those functions in the jaus.cpp.
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  6. #6
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Undefined Reference to vtable

    Thanks for the info -- I moved the constructor to public: but I still get the same error

  7. #7
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Undefined Reference to vtable

    I copy pasted the code you gave. I moved the constructor to public, provided the implementation for the functions I told in the previous post ( put in the .cpp file eg.
    void Jaus_neighbor:repare_header() {} and so on) and compiled with success!
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  8. #8
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Undefined Reference to vtable

    well that's just not fair then!

    here's my new .cpp file (and i moved the constructor):
    Qt Code:
    1. #include "jaus.h"
    2.  
    3. Jaus_neighbor::Jaus_neighbor()
    4. {
    5. udpSocket = new QUdpSocket(this);
    6. for (int i = 0; i < 4; i++)
    7. {
    8. header.dest_id[i] = 0;
    9. header.source_id[i] = 0;
    10. }
    11. header.sequence_num = 0;
    12. header.data_control = 0;
    13. header.message_properties = 0;
    14. header.command_code = 0;
    15. }
    16.  
    17. void Jaus_neighbor::startBroadcasting()
    18. {
    19.  
    20. }
    21.  
    22. void Jaus_neighbor::stopBroadcasting()
    23. {
    24.  
    25. }
    26.  
    27. void Jaus_neighbor::sendDatagram()
    28. {
    29. //udpSocket->writeDatagram(message, QHostAddress::LocalHost, 9000);
    30. }
    31.  
    32.  
    33. void Jaus_neighbor::handshake()
    34. {
    35. Jaus_neighbor::startBroadcasting();
    36. }
    37.  
    38. void Jaus_neighbor::prepare_header(){}
    39. void Jaus_neighbor::read_jheader(){}
    40. void Jaus_neighbor::send_jheader(){}
    41. void Jaus_neighbor::do_command(){}
    To copy to clipboard, switch view to plain text mode 

    Same error though

  9. #9
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Qt Undefined Reference to vtable

    What are the differences with the code you'll find in the .zip??
    Also did you rerun qmake?
    Attached Files Attached Files
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  10. #10
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Undefined Reference to vtable

    Ok, here's what happened -- I ran your code and it compiled fine but no command line popped up, so I ran it again... now I get the same error every time with your code. I tried to run qmake, but it keeps saying unknown command.

    This is frustrating

    Also, I just noticed our .pro files are different... not sure if that matters:

    mine:
    Qt Code:
    1. # -------------------------------------------------
    2. # Project created by QtCreator 2010-02-24T13:23:24
    3. # -------------------------------------------------
    4. QT += network
    5. QT -= gui
    6. TARGET = jausCommandLine
    7. CONFIG += console
    8. CONFIG -= app_bundle
    9. TEMPLATE = app
    10. SOURCES += main.cpp \
    11. jaus.cpp
    12. HEADERS += jaus.h
    To copy to clipboard, switch view to plain text mode 

    yours:
    Qt Code:
    1. QT += network
    2.  
    3. TARGET = jaus
    4. TEMPLATE = app
    5.  
    6.  
    7. SOURCES += main.cpp\
    8. jaus.cpp
    9.  
    10. HEADERS += jaus.h
    To copy to clipboard, switch view to plain text mode 
    Last edited by ctote; 24th February 2010 at 21:40.

  11. #11
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Undefined Reference to vtable

    Just changed my .pro file for yours (except I added the CONFIG section for my command line) -- it's working great now. Why? I'm very new to Qt and don't quite understand the requirements in the .pro file (as well as the requirements for object creation e.g., Q_OBJECT).

  12. #12
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Similar Threads

  1. undefined reference to vtable in Threads.
    By prasanth.nvs in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 20th February 2009, 10:19
  2. Undefined reference to 'vtable for XXX'
    By Sheng in forum Qt Programming
    Replies: 4
    Last Post: 17th October 2008, 15:59
  3. undefined reference to vtable
    By renjithmamman in forum Qt Programming
    Replies: 5
    Last Post: 2nd July 2006, 04:23
  4. Replies: 2
    Last Post: 30th June 2006, 18:42

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
  •  
Qt is a trademark of The Qt Company.