Results 1 to 3 of 3

Thread: Undefined reference

  1. #1
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Undefined reference

    Hey all,

    I am trying to create a plugin for my program so i created a abstract class for an interface, i followed the echoplugin example. But the compiler keeps complaining about an "undefined reference to `vtable for ScrapperInterface'".

    This is the complete error i get:
    Qt Code:
    1. debug/moc_themoviedb.o: In function `~ScrapperInterface':
    2. g:\projects\DuneInterface-build-desktop\ScrapperPlugins\TheMovieDb/../../../DuneInterface/movieWall/scrapperinterface.h:30: undefined reference to `vtable for ScrapperInterface'
    3. collect2: ld returned 1 exit status
    4. mingw32-make[3]: *** [debug/scrapperplugind.dll] Error 1
    5. mingw32-make[2]: *** [debug] Error 2
    6. mingw32-make[1]: *** [sub-TheMovieDb-make_default] Error 2
    7. mingw32-make: *** [sub-ScrapperPlugins-make_default] Error 2
    8. The process "E:\Qt\2010.05\mingw\bin\mingw32-make.exe" exited with code 2.
    9. Error while building project DuneInterface (target: Desktop)
    10. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 


    This is the interface i have created:
    Qt Code:
    1. #ifndef SCRAPPERINTERFACE_H
    2. #define SCRAPPERINTERFACE_H
    3.  
    4. #include <QString>
    5.  
    6. #include "moviedetails.h"
    7.  
    8. class ScrapperInterface
    9. {
    10. public:
    11. virtual ~ScrapperInterface() {}
    12. virtual QString siteName() = 0;
    13. virtual QString siteAddress() = 0;
    14. virtual int getMovieDetails(QString movieTitle) = 0;
    15.  
    16. signals:
    17. virtual int movieData();
    18. };
    19.  
    20. Q_DECLARE_INTERFACE(ScrapperInterface,
    21. "Esquirol.Plugin.Scrapper/1.0");
    22. #endif // SCRAPPERINTERFACE_H
    To copy to clipboard, switch view to plain text mode 

    And this is the code for the plugin that implements the interface:
    .h
    Qt Code:
    1. #ifndef THEMOVIEDB_H
    2. #define THEMOVIEDB_H
    3.  
    4. #include <QString>
    5. #include <QObject>
    6. #include <QXmlStreamReader>
    7. #include <QtNetwork>
    8.  
    9. #include "themoviedb.h"
    10. #include "scrapperinterface.h"
    11. #include "moviedetails.h"
    12.  
    13. class TheMovieDb : public QObject, ScrapperInterface
    14. {
    15. Q_OBJECT
    16. Q_INTERFACES(ScrapperInterface)
    17.  
    18. public:
    19. ~TheMovieDb() {}
    20. QString siteName();
    21. QString siteAddress();
    22. int getMovieDetails(QString movieTitle);
    23.  
    24. signals:
    25. int movieData();
    26.  
    27. public slots:
    28. void replyFinished(QNetworkReply *reply);
    29.  
    30. private:
    31. void fetch();
    32.  
    33. static const QString apiKey() { return "text"; }
    34.  
    35. QXmlStreamReader xml;
    36. QNetworkAccessManager http;
    37. };
    38.  
    39. #endif // THEMOVIEDB_H
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include "themoviedb.h"
    2. #include <QDebug>
    3.  
    4. QString TheMovieDb::siteName()
    5. {
    6. return "themoviedb.org";
    7. }
    8.  
    9. QString TheMovieDb::siteAddress()
    10. {
    11. return "http://www.themoviedb.org";
    12. }
    13.  
    14. int TheMovieDb::getMovieDetails(QString movieTitle)
    15. {
    16. qDebug() << "int TheMovieDb::getMovieDetails(QString movieTitle)";
    17.  
    18. return 0;
    19. }
    20.  
    21. void TheMovieDb::replyFinished(QNetworkReply *reply)
    22. {
    23. qDebug() << "void TheMovieDb::replyFinished(QNetworkReply *reply)";
    24. }
    To copy to clipboard, switch view to plain text mode 

    I know that an undefined reference means that i still have to implement one function but i thought i implemented everything the interface specifies.

    Hope you can help me

    Regards,
    Marcel

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference

    Signals and slots can only be used with QObject subclasses, which call the Q_OBJECT macro.
    See your ScrapperInterface class - its not a QObject, and it doesn't call the Q_OBJECT macro, and that is the reason for the error you are getting.
    I actually never tried putting signals/slots in an interface, so I am not even sure it will work for you (the plugin framework) if you do that, but you can try.
    EDIT:
    Now that I think of it, it should not work, since as soon as you subclass a non abstract class (QObject) your interface is not an interface any more.

    You will have to implement the signal slots in the object that implement the interface.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    eekhoorn12 (6th January 2011)

  4. #3
    Join Date
    Jun 2007
    Location
    Netherlands
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined reference

    Thanks, that problem is now fixed, but i still can't seem to load my plugin.

    K Fixed the problem that was stated below. Forgot the Q_EXPORT_PLUGIN2 line.


    When i try to load the plugin i get the error:
    Qt Code:
    1. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/scrapperplugind.dll' is not a valid Qt plugin."
    To copy to clipboard, switch view to plain text mode 

    I load the plugins with the following code:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. QDir pluginsDir(qApp->applicationDirPath());
    8.  
    9. qDebug() << pluginsDir;
    10. foreach (QString filename, pluginsDir.entryList(QDir::Files))
    11. {
    12. qDebug() << filename;
    13. qDebug() << pluginsDir.absoluteFilePath(filename);
    14. QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(filename));
    15. QObject *plugin = pluginLoader.instance();
    16. qDebug() << pluginLoader.errorString();
    17. if (plugin) {
    18. qDebug() << "2";
    19. scrapperInterface = qobject_cast<ScrapperInterface *>(plugin);
    20. if(scrapperInterface)
    21. {
    22. qDebug() << "3";
    23. }
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    which gives the following output:
    Qt Code:
    1. QDir( "G:/projects/DuneInterface-build-desktop/movieWall/debug" , nameFilters = { * }, QDir::SortFlags( Name | IgnoreCase ) , QDir::Filters( Dirs|Files|Drives|AllEntries ) )
    2. "main.o"
    3. "G:/projects/DuneInterface-build-desktop/movieWall/debug/main.o"
    4. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/main.o' is not a valid Qt plugin."
    5. "mainwindow.o"
    6. "G:/projects/DuneInterface-build-desktop/movieWall/debug/mainwindow.o"
    7. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/mainwindow.o' is not a valid Qt plugin."
    8. "moc_mainwindow.cpp"
    9. "G:/projects/DuneInterface-build-desktop/movieWall/debug/moc_mainwindow.cpp"
    10. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/moc_mainwindow.cpp' is not a valid Qt plugin."
    11. "moc_mainwindow.o"
    12. "G:/projects/DuneInterface-build-desktop/movieWall/debug/moc_mainwindow.o"
    13. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/moc_mainwindow.o' is not a valid Qt plugin."
    14. "movieWall.exe"
    15. "G:/projects/DuneInterface-build-desktop/movieWall/debug/movieWall.exe"
    16. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/movieWall.exe' is not a valid Qt plugin."
    17. "scrapperplugind.dll"
    18. "G:/projects/DuneInterface-build-desktop/movieWall/debug/scrapperplugind.dll"
    19. "The file 'G:/projects/DuneInterface-build-desktop/movieWall/debug/scrapperplugind.dll' is not a valid Qt plugin."
    20. G:\projects\DuneInterface-build-desktop\movieWall\debug\movieWall.exe exited with code 0
    To copy to clipboard, switch view to plain text mode 

    Here scrapperplugind.dll is the plugin i wish to load.

    I was looking the code while debugging and think i found why it doesn't work.

    In the isPlugin function Qt loads the settings from the library and should load with which version of Qt it is build. But it doesn't find that information and i don't know why.
    Last edited by eekhoorn12; 6th January 2011 at 18:18.

Similar Threads

  1. undefined reference
    By digidas in forum Newbie
    Replies: 9
    Last Post: 19th May 2010, 13:04
  2. undefined reference
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:45
  3. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 08:34
  4. Undefined Reference To...
    By ManuMies in forum Qt Programming
    Replies: 6
    Last Post: 10th February 2009, 12:14
  5. Undefined reference
    By Salazaar in forum Newbie
    Replies: 12
    Last Post: 23rd May 2007, 10:21

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.