[Qt-interest] Qt plugin error: undefined reference to `MainWindow::staticMetaObject'

程梁 chengliang.soft at gmail.com
Wed Apr 28 10:43:36 CEST 2010


Thanks! I found the problem is I forgot add mainwindow.h into app.pro.
Then I added the HEADERS, recompiled and there is no such an error.

But I got the other error:
debug/moc_mainwindow.o:moc_mainwindow.cpp:...: undefined reference to
`MainWindow::~MainWindow()'

debug/moc_mainwindow.o:moc_mainwindow.cpp:...: undefined reference to
`MainWindow::~MainWindow()'

debug/moc_mainwindow.o:moc_mainwindow.cpp:...: undefined reference to
`MainWindow::changeEvent(QEvent*)'

debug/moc_mainwindow.o:moc_mainwindow.cpp:...: undefined reference to
`non-virtual thunk to MainWindow::~MainWindow()'

debug/moc_mainwindow.o:moc_mainwindow.cpp:...: undefined reference to
`non-virtual thunk to MainWindow::~MainWindow()'

It seems that Qt try to compile the plugin staticly. Could you help me?
Thanks!

I'll paste the code.

The directory is as following:

/ --- test.pro
  |
 ui ---- ui.pro
  |   | -- mainwindow.h
  |   | -- mainwindow.cpp
  |   | -- IVisible.h // this contains the interface that has only two
functions: setVisible(bool) and visible()
  |
app ----- app.pro
       | --- main.cpp
       | --- mainwindow.h // copy from ui/mainwindow.h

mainwindow.h is

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "IVisible.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow, IVisible {
    Q_OBJECT
    Q_INTERFACES(IVisible)

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void setVisible(bool v)
    {
        this->setVisible(v);
    }

    bool visible() const
    {
        return this->visible();
    }

protected:
    void changeEvent(QEvent *e);

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

test.pro
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = ui app

app.pro
TARGET = tt
TEMPLATE = app
INCLUDEPATH += ../ui
SOURCES += main.cpp
HEADERS += mainwindow.h

ui.pro
TARGET = ui
TEMPLATE = lib
CONFIG += plugin
DESTDIR = ../app/plugins
SOURCES += mainwindow.cpp
HEADERS += mainwindow.h \
    IVisible.h
FORMS += mainwindow.ui

2010/4/28 Thiago Macieira <thiago at kde.org>

> Em Quarta-feira 28. Abril 2010, às 08.39.04, 程梁 escreveu:
> >
> D:/Develop/Qt/2010.02.1/qt/include/QtCore/../../src/corelib/kernel/qobject.
> > h:455: undefined reference to `MainWindow::staticMetaObject'
>
> > int main(int argc, char *argv[])
> > {
> >     QApplication a(argc, argv);
> >     QPluginLoader pluginLoader("ui.dll");
> >     if(pluginLoader.load()) {
> >         QObject *obj = pluginLoader.instance();
> >         QMessageBox::information(NULL, "plugin",
> > obj->metaObject()->className());
> >         // MainWindow *win = qobject_cast<MainWindow *>(obj);
> >         // win->setVisible(true);
> >     }
> >     return a.exec();
> > }
> >
> > Could you tell me how to solve this problem? Thank you!
>
> Where is MainWindow defined? From the error you're getting, the .h header
> includes a Q_OBJECT macro.
>
> Is the header listed in the HEADERS line for the library? Is the
> application
> above linked to that library?
>
> Do you even have a library?
>
> Remember, when you have a plugin, you MUST have two components at least:
>  1) a library
>  2) the plugin
>  3) optional: an application
>
> You pasted the code above for the optional part. Where's the library? Both
> the
> plugin and the application must link to this library.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>  Senior Product Manager - Nokia, Qt Development Frameworks
>      PGP/GPG: 0x6EF45358; fingerprint:
>      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>


-- 
Cheng Liang
from: chengliang.soft at gmail.com



-- 
Cheng Liang
from: chengliang.soft at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100428/e9859def/attachment.html 


More information about the Qt-interest-old mailing list