Important: Please read the Qt Code of Conduct -

Linker error with custom widgets

  • hey i am getting a linker error when installing a custom widget
    plus my widget is not visible in qtcreator and only visible in qt designer . please help me . i have used qt5.0 in win 7 and msvc compiler

    linker errors are of this kind
    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall AnalogClock::AnalogClock(class QWidget *)" (_imp??0AnalogClock@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QAEXPAVQMainWindow@@@Z)

    please help

  • Hi,

    It looks like the symbols have not been exported when compiling AnalogClock. Could you please show the class declaration?

  • #include <QDesignerCustomWidgetInterface>

    class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface" FILE "analogclock.json")
    AnalogClockPlugin(QObject *parent = 0);

    bool isContainer() const;
    bool isInitialized() const;
    QIcon icon() const;
    QString domXml() const;
    QString group() const;
    QString includeFile&#40;&#41; const;
    QString name(&#41; const;
    QString toolTip() const;
    QString whatsThis() const;
    QWidget *createWidget(QWidget *parent);
    void initialize(QDesignerFormEditorInterface *core);

    bool initialized;

    though this is same as the custom widgetsexample of qt i have tried various versions but none are working
    this is the pro file of my executing file

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = tester
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui
    INCLUDEPATH += "C:\Qt\Qt5.0.1\5.0.1\msvc2010\examples\designer\customwidgetplugin"

    i had also added the libs path but on that the program terminates without any reason

    LIBS +=-L"C:\Qt\Qt5.0.1\Tools\QtCreator\bin\tester" -l"customwidgetplugin"

  • If you try this:
    #define MY_API Q_DECL_EXPORT
    #define MY_API Q_DECL_IMPORT

    class MY_API AnalogClockPlugin

    while adding EXPORT_MY_PLUGIN in the defines of your plugin project, does it change something?

  • no the file is not compiling even and well the code is actually qt example only
    so i think it is the deployment and installing which is the problem

Log in to reply