Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem building when including a custom widget collection in Qt Creator
QtWS25 Last Chance

Problem building when including a custom widget collection in Qt Creator

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 7.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deus_duke
    wrote on last edited by
    #1

    I am having a problem trying to build a Qt application that includes custom widget that is part of a CW collection. It's strange because if I open the ui file in Qt Designer and do a preview run, it works fine. The custom widget is just a label that you can click on to browse the file system and select a file.

    I am using Qt version 4.6.3

    Here is my .pro for the application

    @#-------------------------------------------------

    Project created by QtCreator 2010-08-24T17:00:51

    #-------------------------------------------------

    QT += core gui

    TARGET = BesoQt
    TEMPLATE = app

    INCLUDEPATH = ../CustomWidgets
    #LIBS = -L -lmdcustomwidgetsplugin
    #win32:LIBS += D:/Lynx/CustomWidgets-build-desktop/release/mdcustomwidgetsplugin.dll

    SOURCES +=
    projectdialog.cpp
    mainwindow.cpp
    main.cpp

    HEADERS +=
    projectdialog.h
    mainwindow.h

    FORMS +=
    projectdialog.ui
    mainwindow.ui

    RESOURCES +=
    resources.qrc
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deus_duke
      wrote on last edited by
      #2

      And here is the compilation output

      @Running build steps for project CustomWidgets...
      Configuration unchanged, skipping qmake step.
      Starting: "D:/MinGW/bin/mingw32-make.exe" -w
      mingw32-make: Entering directory D:/Lynx/CustomWidgets-build-desktop' D:/MinGW/bin/mingw32-make -f Makefile.Release mingw32-make[1]: Entering directory D:/Lynx/CustomWidgets-build-desktop'
      mingw32-make[1]: Nothing to be done for first'. mingw32-make[1]: Leaving directory D:/Lynx/CustomWidgets-build-desktop'
      mingw32-make: Leaving directory D:/Lynx/CustomWidgets-build-desktop' The process "D:/MinGW/bin/mingw32-make.exe" exited normally. Starting: "D:/MinGW/bin/mingw32-make.exe" install -w mingw32-make: Entering directory D:/Lynx/CustomWidgets-build-desktop'
      D:/MinGW/bin/mingw32-make -f Makefile.Release install
      mingw32-make[1]: Entering directory D:/Lynx/CustomWidgets-build-desktop' copy /y "releasemdcustomwidgetsplugin.dll" "d:Qt2010.04qtpluginsdesignermdcustomwidgetsplugin.dll" 1 file(s) copied. mingw32-make[1]: Leaving directory D:/Lynx/CustomWidgets-build-desktop'
      mingw32-make: Leaving directory D:/Lynx/CustomWidgets-build-desktop' The process "D:/MinGW/bin/mingw32-make.exe" exited normally. Running build steps for project BesoQt... Starting: "d:/qt/2010.04/qt/bin/qmake.exe" D:/Lynx/BesoQt/BesoQt.pro -r -spec win32-g++ The process "d:/qt/2010.04/qt/bin/qmake.exe" exited normally. Starting: "D:/MinGW/bin/mingw32-make.exe" -w mingw32-make: Entering directory D:/Lynx/BesoQt-build-desktop'
      D:/MinGW/bin/mingw32-make -f Makefile.Debug
      mingw32-make[1]: Entering directory D:/Lynx/BesoQt-build-desktop' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -o debugprojectdialog.o ..BesoQtprojectdialog.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -o debugmainwindow.o ..BesoQtmainwindow.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -o debugmain.o ..BesoQtmain.cpp D:Qt2010.04qtbinmoc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -D__GNUC__ -DWIN32 ..BesoQtprojectdialog.h -o debugmoc_projectdialog.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -o debugmoc_projectdialog.o debugmoc_projectdialog.cpp D:Qt2010.04qtbinmoc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -D__GNUC__ -DWIN32 ..BesoQtmainwindow.h -o debugmoc_mainwindow.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -o debugmoc_mainwindow.o debugmoc_mainwindow.cpp d:Qt2010.04qtbinrcc.exe -name resources ..BesoQtresources.qrc -o debugqrc_resources.cpp g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"....Qt2010.04qtincludeQtCore" -I"....Qt2010.04qtincludeQtGui" -I"....Qt2010.04qtinclude" -I"..CustomWidgets" -I"....Qt2010.04qtincludeActiveQt" -I"debug" -I"." -I"..BesoQt" -I"." -I"....Qt2010.04qtmkspecswin32-g++" -o debugqrc_resources.o debugqrc_resources.cpp g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debugBesoQt.exe debug/projectdialog.o debug/mainwindow.o debug/main.o debug/moc_projectdialog.o debug/moc_mainwindow.o debug/qrc_resources.o -L"d:Qt2010.04qtlib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4 mingw32-make[1]: Leaving directory D:/Lynx/BesoQt-build-desktop'
      mingw32-make: Leaving directory D:/Lynx/BesoQt-build-desktop' debug/projectdialog.o:D:LynxBesoQt-build-desktop/./ui_projectdialog.h:95: undefined reference to BrowseLabel::BrowseLabel(QWidget*)'
      collect2: ld returned 1 exit status
      mingw32-make[1]: *** [debugBesoQt.exe] Error 1
      mingw32-make: *** [debug] Error 2
      The process "D:/MinGW/bin/mingw32-make.exe" exited with code %2.
      Error while building project BesoQt (target: Desktop)
      When executing build step 'Make'@

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        The compilation works, so the header is found. This means your INCLUDEPATH is set up correctly.

        You get an linker error, so the binary (either a library or the object file) is not linked into your target. That hints to the LIBS variable being messed up.

        Looking at the commented out LIBS: Do you actually have a library containing your custom widget? It looks like you only build a designer plugin.

        If your widget is not depending on more customwidgets you might be able to get away with just adding the .cpp file of your widget to the SOURCES. Not necessarily the cleanest approach, but sometimes less work than building a (static or shared) library:-)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          deus_duke
          wrote on last edited by
          #4

          Tobias Hunger, thank you so much for your response.

          I was trying to include the same dll that gets installed into the qt designer directory....which I am guessing was the wrong thing to do.

          I commented out the LIBS that I had because I realized that they were not working.

          How do I go about building the actual library that contains my custom widget collection and not just the designer plugin? Can this be kicked out in the custom widget collection library project, or do I have to build each custom widget individually into it's own library.

          I need this application to have a control library because soon it will become rather large. Also the same controls will be used in another application that runs alongside this one.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            Just put everything into one shared library and leave out the designer integration code:-) Should be straight forward to do with the designer plugin already working.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deus_duke
              wrote on last edited by
              #6

              Forgive my ignorance because this is still my first week giving Qt a serious look.

              bq. Just put everything into one shared library and leave out the designer integration code

              By this, do you mean leave out the 'designer' option in the CWC .pro file's CONFIG?

              @CONFIG += designer plugin debug_and_release
              TARGET = $$qtLibraryTarget(mdcustomwidgetsplugin)
              TEMPLATE = lib

              HEADERS = browselabelplugin.h projectwidgetplugin.h mdcustomwidgets.h
              SOURCES = browselabelplugin.cpp projectwidgetplugin.cpp mdcustomwidgets.cpp
              RESOURCES = resources.qrc
              LIBS += -L.

              target.path = $$[QT_INSTALL_PLUGINS]/designer
              INSTALLS += target

              include(browselabel.pri)
              include(projectwidget.pri)
              @

              Or do you mean go through each header and source and remove the includes and macros

              So from this:
              @#ifndef BROWSELABELPLUGIN_H
              #define BROWSELABELPLUGIN_H

              #include <QDesignerCustomWidgetInterface>

              class BrowseLabelPlugin : public QObject, public QDesignerCustomWidgetInterface
              {
              Q_OBJECT
              Q_INTERFACES(QDesignerCustomWidgetInterface)

              public:
              explicit BrowseLabelPlugin(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() const;
              QString toolTip() const;
              QString whatsThis() const;
              QWidget *createWidget(QWidget *parent);
              void initialize(QDesignerFormEditorInterface *core);
              

              private:
              bool m_initialized;
              };

              #endif
              @

              I would remove :

              • #include <QDesignerCustomWidgetInterface>
              • public QDesignerCustomWidgetInterface
              • Q_INTERFACES(QDesignerCustomWidgetInterface)
              • void initialize(QDesignerFormEditorInterface *core);
              1 Reply Last reply
              0
              • T Offline
                T Offline
                tobias.hunger
                wrote on last edited by
                #7

                You should not need the *Plugin classes at all. Those are the actual integration of your custom widgets into the Designer UI.

                So you should be fine with an new customwidgets.pro file containing the following (UNTESTED!):

                @
                TARGET = $$qtLibraryTarget(mdcustomwidgets)
                TEMPLATE = lib

                include(browselabel.pri)
                include(projectwidget.pri)
                @

                Provided that browselabel.pri and projectwidget.pri are containing the headers and sources of the widgets you want.

                You could even change the .pro-file of the plugins afterwards to link against your new library, replacing the include lines with the appropriate library information:-)

                The relevant documentation can be found "here":http://doc.qt.nokia.com/4.7-snapshot/designer-creating-custom-widgets.html.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  deus_duke
                  wrote on last edited by
                  #8

                  Great! Thanks for you assistance, I should be able to get it working with this information.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    glafauci61
                    wrote on last edited by
                    #9

                    Hello to everybody.
                    I have the same problem of Deus Duke. I try to lead the same solution that Tobias suggest, but... don't works. Why?

                    Here i explain my steps:

                    1. I create a Qt Designer plugin that works fine in Qt Designer (KLineEditEx).

                    2. I create a new Qt Creator project with this .pro file:

                    @QT += core gui
                    TARGET = $$qtLibraryTarget(Kwidgets)
                    TEMPLATE = lib

                    include(klineedit.pri)@

                    1. I create the klineedit.pri file:

                    @INCLUDEPATH += C:/Documents and Settings/glafauci/Documenti/Programmi QT/KLineEditEx
                    HEADERS += ../KLineEditEx/klineeditex.h
                    SOURCES += ../KLineEditEx/klineeditex.cpp@

                    When I attempt to build this project, I have this answer from the compiler:

                    @Running build steps for project KWidgets...
                    Configuration unchanged, skipping qmake step.
                    Starting: "C:/Programmi/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
                    mingw32-make: Entering directory `C:/Documents and Settings/glafauci/Documenti/Programmi QT/KWidgets-build-desktop'

                    C:/Programmi/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug

                    mingw32-make[1]: Entering directory `C:/Documents and Settings/glafauci/Documenti/Programmi QT/KWidgets-build-desktop'

                    g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -shared -Wl,--out-implib,debug\libKwidgets.a -o debug\Kwidgets.dll debug/klineeditex.o debug/moc_klineeditex.o -L"c:\Programmi\Qt\2010.05\qt\lib" -lQtGuid4 -lQtCored4

                    debug/klineeditex.o: In function `KLineEditEx':

                    C:\Documents and Settings\glafauci\Documenti\Programmi QT\KWidgets-build-desktop/../KLineEditEx/klineeditex.cpp:49: undefined reference to `_imp___ZTV11KLineEditEx'

                    C:\Documents and Settings\glafauci\Documenti\Programmi QT\KWidgets-build-desktop/../KLineEditEx/klineeditex.cpp:49: undefined reference to `_imp___ZTV11KLineEditEx'

                    C:\Documents and Settings\glafauci\Documenti\Programmi QT\KWidgets-build-desktop/../KLineEditEx/klineeditex.cpp:49: undefined reference to `_imp___ZTV11KLineEditEx'

                    C:\Documents and Settings\glafauci\Documenti\Programmi QT\KWidgets-build-desktop/../KLineEditEx/klineeditex.cpp:49: undefined reference to `_imp___ZTV11KLineEditEx'

                    debug/moc_klineeditex.o:C:\Documents and Settings\glafauci\Documenti\Programmi QT\KWidgets-build-desktop/debug/moc_klineeditex.cpp:72: undefined reference to `_imp___ZN11KLineEditEx16staticMetaObjectE'

                    debug/moc_klineeditex.o: In function `_static_initialization_and_destruction_0':

                    Creating library file: debug\libKwidgets.a

                    mingw32-make[1]: Leaving directory `C:/Documents and Settings/glafauci/Documenti/Programmi QT/KWidgets-build-desktop'

                    mingw32-make: Leaving directory `C:/Documents and Settings/glafauci/Documenti/Programmi QT/KWidgets-build-desktop'

                    C:\Documents and Settings\glafauci\Documenti\Programmi QT\KWidgets-build-desktop/debug/moc_klineeditex.cpp:64: undefined reference to `_imp___ZN11KLineEditEx16staticMetaObjectE'

                    collect2: ld returned 1 exit status

                    mingw32-make[1]: *** [debug\Kwidgets.dll] Error 1

                    mingw32-make: *** [debug] Error 2

                    The process "C:/Programmi/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
                    Error while building project KWidgets (target: Desktop)
                    When executing build step 'Make'@

                    What happens?

                    Thanks to all.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved