Plugin para o Qt Designer e Cmake



  • Em primeiro lugar, quero agradecer a oportunidade de participar do Forum, e me apresentar aos participantes, meu nome é Rodolfo, e desenvolvo em Qt já a sete anos.

    Estou tentando compilar um plugin para o Designer no Windows, utilizando o
    Cmake, sem sucesso.
    No Linux, compilou corretamente e gerou o plugin para o Designer, no Windows
    não.
    O código é baseado no exemplo World Time Clock Plugin Example.

    No Windows, com o QMake utilizando um arquivo .pro, consegui gerar o plugin,mas
    meu projeto todo e baseado em Cmake, e o aplicativo não compila com o plugin
    gerado por Qmake.

    Running build steps for project focuslineedit...
    Starting: "C:\MinGW\bin\mingw32-make.exe"
    [ 16%] Generating moc_focuslineeditplugin.cxx
    [ 33%] Generating moc_focusLineEdit.cxx
    [ 50%] Building CXX object CMakeFiles/focuslineedit.dir/focusLineEdit.cpp.obj
    C:\SistemasQT\Classes_e_Funcoes\plugins\focuslineedit\focusLineEdit.cpp:4:1:
    warning: 'focusLineEdit::focusLineEdit(QWidget*)' redeclared without dllimport
    attribute: previous dllimport ignored
    C:\SistemasQT\Classes_e_Funcoes\plugins\focuslineedit\focusLineEdit.cpp:8:1:
    warning: 'virtual focusLineEdit::~focusLineEdit()' redeclared without dllimport
    attribute: previous dllimport ignored
    C:\SistemasQT\Classes_e_Funcoes\plugins\focuslineedit\focusLineEdit.cpp:12:6:
    warning: 'virtual void focusLineEdit::focusOutEvent(QFocusEvent*)' redeclared
    without dllimport attribute: previous dllimport ignored
    [ 66%] Building CXX object
    CMakeFiles/focuslineedit.dir/focuslineeditplugin.cpp.obj
    [ 83%] Building CXX object
    CMakeFiles/focuslineedit.dir/moc_focusLineEdit.cxx.obj
    C:\SistemasQT\Classes_e_Funcoes\plugins\qtcreator-build\moc_focusLineEdit.cxx:43
    :34: warning: 'focusLineEdit::staticMetaObject' redeclared without dllimport
    attribute after being referenced with dll linkage
    C:\SistemasQT\Classes_e_Funcoes\plugins\qtcreator-build\moc_focusLineEdit.cxx:52
    :20: warning: 'virtual const QMetaObject* focusLineEdit::metaObject() const'
    redeclared without dllimport attribute: previous dllimport ignored
    C:\SistemasQT\Classes_e_Funcoes\plugins\qtcreator-build\moc_focusLineEdit.cxx:57
    :7: warning: 'virtual void* focusLineEdit::qt_metacast(const char*)' redeclared
    without dllimport attribute: previous dllimport ignored
    C:\SistemasQT\Classes_e_Funcoes\plugins\qtcreator-build\moc_focusLineEdit.cxx:65
    :5: warning: 'virtual int focusLineEdit::qt_metacall(QMetaObject::Call, int,
    void**)' redeclared without dllimport attribute: previous dllimport ignored
    C:\SistemasQT\Classes_e_Funcoes\plugins\qtcreator-build\moc_focusLineEdit.cxx:81
    :6: warning: 'void focusLineEdit::focusOut(bool)' redeclared without dllimport
    attribute after being referenced with dll linkage
    [100%] Building CXX object
    CMakeFiles/focuslineedit.dir/moc_focuslineeditplugin.cxx.obj
    Linking CXX shared library libfocuslineedit.dll
    Creating library file: libfocuslineedit.dll.a
    CMakeFiles\focuslineedit.dir/objects.a(focusLineEdit.cpp.obj):focusLineEdit.cpp:
    (.text+0x1b): undefined reference to _imp___ZTV13focusLineEdit' CMakeFiles\focuslineedit.dir/objects.a(focusLineEdit.cpp.obj):focusLineEdit.cpp:\ (.text+0x28): undefined reference to_imp___ZTV13focusLineEdit'
    CMakeFiles\focuslineedit.dir/objects.a(focusLineEdit.cpp.obj):focusLineEdit.cpp:
    (.text+0x41): undefined reference to _imp___ZTV13focusLineEdit' CMakeFiles\focuslineedit.dir/objects.a(focusLineEdit.cpp.obj):focusLineEdit.cpp:\ (.text+0x4e): undefined reference to_imp___ZTV13focusLineEdit'
    CMakeFiles\focuslineedit.dir/objects.a(focusLineEdit.cpp.obj):focusLineEdit.cpp:
    (.text+0xdb): undefined reference to _imp___ZN13focusLineEdit8focusOutEb' CMakeFiles\focuslineedit.dir/objects.a(focuslineeditplugin.cpp.obj):focuslineedi\ tplugin.cpp:(.text+0x99): undefined reference to_imp___ZN13focusLineEditC1EP7QWidget'
    CMakeFiles\focuslineedit.dir/objects.a(moc_focusLineEdit.cxx.obj):moc_focusLineE
    dit.cxx:(.text+0x2f): undefined reference to
    _imp___ZN13focusLineEdit16staticMetaObjectE' CMakeFiles\focuslineedit.dir/objects.a(moc_focusLineEdit.cxx.obj):moc_focusLineE\ dit.cxx:(.text+0x106): undefined reference to_imp___ZN13focusLineEdit16staticMetaObjectE'
    CMakeFiles\focuslineedit.dir/objects.a(moc_focusLineEdit.cxx.obj):moc_focusLineE
    dit.cxx:(.text+0x145): undefined reference to
    `_imp___ZN13focusLineEdit16staticMetaObjectE'
    collect2: ld returned 1 exit status
    mingw32-make[2]: *** [libfocuslineedit.dll] Error 1
    mingw32-make[1]: *** [CMakeFiles/focuslineedit.dir/all] Error 2
    mingw32-make: *** [all] Error 2
    The process "C:\MinGW\bin\mingw32-make.exe" exited with code 2.
    Error while building project focuslineedit (target: Desktop)
    When executing build step 'Make'

    //////////////////////////////////////////////////////////////////
    CMakeLists.txt

    project(focuslineedit)
    cmake_minimum_required(VERSION 2.6)
    find_package(Qt4 REQUIRED)

    ADD_DEFINITIONS(${QT_DEFINITIONS})
    ADD_DEFINITIONS(-DQT_PLUGIN)
    ADD_DEFINITIONS(-DQT_NO_DEBUG)
    ADD_DEFINITIONS(-DQT_SHARED)

    include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

    set(focuslineedit_SRCS focusLineEdit.cpp focuslineeditplugin.cpp)

    qt4_wrap_cpp(focuslineedit_SRCS focusLineEdit.h focuslineeditplugin.h)

    qt4_automoc(${focuslineedit_SRCS})

    #add_library(teste ${teste_SRCS})

    add_library(focuslineedit SHARED ${focuslineedit_SRCS}
    ${focuslineedit_MOC_SRCS})

    target_link_libraries(focuslineedit ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})



  • Olá Rodolfo,

    Já encontrou solução para seu problema? Tem um tempão que vc postou aqui né?
    Recentemente andei lidando com problemas na compilação no Windows. Algumas libs que criei estavam ok no Linux, porém apresentavam erro no linker quando ao compilar no Windows, com msvc.

    Dê uma olhada no uso das macros Q_DECL_IMPORT e Q_DECLR_EXPORT, pode ajudar ;)



  • Obrigado, Anselmo, por enquanto não achei solução, vou dar uma pesquisada na sua sugestão.



  • Bem Ansemo, pesquisei sua sugestão de uso da macros, na própria documentação da Qt tem exemplo:

    http://doc.qt.nokia.com/4.8-snapshot/sharedlibrary.html

    No entanto, eu acho que o plugin para o designer é uma dll “especial”, tentei utilizar este esquema sugerido pela documentação, mas no header do meu plugin, onde eu devo colocar a referencia ao segundo header, minhalib_global.h , já deve haver a referencia ao plugin, no meu caso:

    #ifndef FOCUSLINEEDIT_H
    #define FOCUSLINEEDIT_H

    #include <QLineEdit>
    #include <QObject>
    #include <QtDesigner/QDesignerExportWidget>

    class QDESIGNER_WIDGET_EXPORT focusLineEdit : public QLineEdit
    {
    Q_OBJECT

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

    signals:
    void focusOut(bool hasFocus);

    protected:
    virtual void focusOutEvent(QFocusEvent *e);

    };

    #endif

    Pela sugestão da documentação, deveria ser:

    mysharedlib_global.h,

    #include <QtCore/QtGlobal>

    #if defined(MYSHAREDLIB_LIBRARY)

    define MYSHAREDLIB_EXPORT Q_DECL_EXPORT

    #else

    define MYSHAREDLIB_EXPORT Q_DECL_IMPORT

    #endif
    Então, meu plugin seria:
    #include "mysharedlib_global.h"

    class MYSHAREDLIB_EXPORT focusLineEdit : public QlineEdit
    Acho que este esquma serve para compilar uma ddl normal, mas para um plugin para o designer não.
    A proposito, na documentação do Cmake também tem referencia a compilar dll:
    http://www.cmake.org/Wiki/BuildingWinDLL


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.