Results 1 to 6 of 6

Thread: mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' error

    Dear Viewer!
    How to solve this problem!
    mythread.o: In function `ThreadDialog::startOrStopThreadB()':
    mythread.cpp:(.text+0x259): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.cpp:(.text+0x2b7): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.o: In function `ThreadDialog::startOrStopThreadA()':
    mythread.cpp:(.text+0x389): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.cpp:(.text+0x3e7): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.o: In function `ThreadDialog::ThreadDialog(QWidget*)':
    mythread.cpp:(.text+0x4ae): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0x4b5): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0x57b): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.cpp:(.text+0x5de): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.cpp:(.text+0x641): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.o: In function `ThreadDialog::ThreadDialog(QWidget*)':
    mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0x8a5): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0x96b): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.cpp:(.text+0x9ce): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.cpp:(.text+0xa31): undefined reference to `ThreadDialog::staticMetaObject'
    mythread.o: In function `main':
    mythread.cpp:(.text+0xcba): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0xcc1): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0xda2): undefined reference to `vtable for ThreadDialog'
    mythread.cpp:(.text+0xda9): undefined reference to `vtable for ThreadDialog'
    collect2: ld returned 1 exit status
    make: *** [mythread] Error 1
    The code is as follows;
    Qt Code:
    1. /*mythread.h*/
    2. #ifndef MYTHREAD_H
    3. #define MYTHREAD_H
    4.  
    5. #include <QtGui>
    6. #include <QString>
    7.  
    8. class MyThread : public QThread
    9. {
    10. Q_OBJECT
    11. volatile bool stopped;
    12. QString msg;
    13.  
    14. public:
    15. MyThread(QObject *parent=0);
    16. void run(); // this is virtual method, we must implement it in our subclass of QThread
    17. void setMessage(const QString &message);
    18. void stop();
    19.  
    20. };
    21. #endif
    22.  
    23. /*mythread.cpp*/
    24. #include "mythread.h"
    25. #include <iostream.h>
    26.  
    27. int i=0;
    28. MyThread::MyThread(QObject *parent)
    29. : QThread(parent)
    30. {
    31. stopped = false;
    32.  
    33. //run();
    34. }
    35.  
    36. void MyThread::run()
    37. {
    38. while (!stopped)
    39. {
    40.  
    41. cerr << qPrintable(msg)<< endl;
    42. msleep(1000);
    43. //if(++i==10)
    44. //stop();
    45. }
    46.  
    47.  
    48.  
    49.  
    50. }
    51.  
    52. void MyThread::stop()
    53. {
    54. stopped = true;
    55. }
    56. void MyThread::setMessage(const QString &message)
    57. {
    58. msg=message;
    59. }
    60.  
    61. class ThreadDialog : public QDialog
    62. {
    63. Q_OBJECT
    64. public:
    65. ThreadDialog(QWidget *parent = 0);
    66. protected:
    67. void closeEvent(QCloseEvent *event);
    68. private slots:
    69. void startOrStopThreadA();
    70. void startOrStopThreadB();
    71. private:
    72. MyThread threadA;
    73. MyThread threadB;
    74. QPushButton *threadAButton;
    75. QPushButton *threadBButton;
    76. QPushButton *quitButton;
    77. };
    78.  
    79. ThreadDialog::ThreadDialog(QWidget *parent)
    80. : QDialog(parent)
    81. {
    82. threadA.setMessage("Anurag");
    83. threadB.setMessage("Sonu");
    84. threadAButton = new QPushButton(tr("Start A"));
    85. threadBButton = new QPushButton(tr("Start B"));
    86. quitButton = new QPushButton(tr("Quit"));
    87. quitButton->setDefault(true);
    88. connect(threadAButton, SIGNAL(clicked()),
    89. this, SLOT(startOrStopThreadA()));
    90. connect(threadBButton, SIGNAL(clicked()),
    91. this, SLOT(startOrStopThreadB()));
    92.  
    93. }
    94.  
    95. void ThreadDialog::startOrStopThreadA()
    96. {
    97. if (threadA.isRunning()) {
    98. threadA.stop();
    99. threadAButton->setText(tr("Start A"));
    100. } else {
    101. threadA.start();
    102. threadAButton->setText(tr("Stop A"));
    103. }
    104. }
    105. void ThreadDialog::startOrStopThreadB()
    106. {
    107. if (threadB.isRunning()) {
    108. threadB.stop();
    109. threadBButton->setText(tr("Start B"));
    110. } else {
    111. threadB.start();
    112. threadBButton->setText(tr("Stop B"));
    113. }
    114. }
    115.  
    116. void ThreadDialog::closeEvent(QCloseEvent *event)
    117. {
    118. threadA.stop();
    119. threadB.stop();
    120. threadA.wait();
    121. threadB.wait();
    122. event->accept();
    123. }
    124.  
    125. int main(int argc, char **argv)
    126. {
    127. QApplication app(argc,argv);
    128. ThreadDialog t;
    129. return app.exec();
    130. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 7th November 2007 at 14:42. Reason: missing [code] tags
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' erro

    Make sure that your .pro file is uptodate.
    (Esp. check that all your .h files are listed after HEADERS += ...;
    and your .cpp files after SOURCES += ...)

    Run qmake again it should work.

    (This error almost always indicates to one of the following:
    * forgotten Q_OBJECT in class declaration
    * missing files in .pro file
    * forgotten to update makefiles
    Resulting in: moc not being run; no Qt-code being generated to implement signals and slots... thus the undefined references.)

    HTH
    Christoph

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' erro

    I have not forgotten Q_OBJECT macro.
    No files is missing to include in .pro files.
    moc files is created as well.
    but application is not running.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' erro

    Is ThreadDialog declared in main.cpp? If so, add this:
    Qt Code:
    1. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    at the end of main.cpp and re-run qmake.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    ashukla (23rd September 2007)

  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' erro

    hi
    clean all the files created by qmake and make and compile freshly whenever u make a change that is realated with virtual table . i have accidently discovered this method ,but i dont know why this works.


    i am using eclipse for qt and hence i dont have trouble in making and cleaning,
    bye

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mythread.cpp:(.text+0x89e): undefined reference to `vtable for ThreadDialog' erro

    Quote Originally Posted by babu198649 View Post
    clean all the files created by qmake and make and compile freshly whenever u make a change that is realated with virtual table . i have accidently discovered this method ,but i dont know why this works.
    All you need is to re-run qmake and you have to do this every time you add or remove Q_OBJECT (or Q_GADGET) macro.

Similar Threads

  1. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  4. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  5. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 19:36

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.