Results 1 to 3 of 3

Thread: How to Implement old ui into new project?

  1. #1
    Join Date
    Jul 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default How to Implement old ui into new project?

    My problem is basically very simple.
    I have built a simple color picker application using Qt Creator 3.4.2 on Windows 7 Sp 1. This application has mutiple forms that are combined in a single widget. This is done through the usual way by inhariting a base class and using qt to build the ui header files.
    I now want to include this application into another project. Trying to do so I imported the header file of the base widget (the one which includes the other parts of the color picker ui).
    However when I try to instantiate an object of this class I get the linker errors (MinGW):
    undefined reference to `ColorPicker::ColorPicker(QWidget*)
    undefined reference to `ColorPicker::~ColorPicker()

    And the a bit more cryptic message with MSVC:
    unresolved external symbol "public: virtual __cdecl ColorPicker::~ColorPicker(void)" (??1ColorPicker@@UEAA@XZ) referenced in function main

    The code that provokes the errors is shown below.
    Qt Code:
    1. #include "dialog.h"
    2. #include <QApplication>
    3. #include <colorpicker.h>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. Dialog w;
    9. w.show();
    10.  
    11. ColorPicker picker;
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 
    The header colorpicker.h is the one that I wrote and that should includes the other classes required to build the Ui.
    It has been placed in a subdirectory of the project and imported using the INCLUDEPATH command in the .pro file. The neccessary ui_classname.h files have been placed in the same folder.
    Its constructor is defined as follows in the header file:
    Qt Code:
    1. explicit ColorPicker(QWidget *parent = 0);
    To copy to clipboard, switch view to plain text mode 
    With the following implementation in the source file
    Qt Code:
    1. ColorPicker::ColorPicker(QWidget *parent) :
    2. QWidget(parent),
    3. ui(new Ui::ColorPicker)
    4. {
    5. ui->setupUi(this);
    6. Some more code ...
    7. }
    To copy to clipboard, switch view to plain text mode 
    Directly using the "ui_classname.h" includes the ui but none of the functionality (like signals and slots)
    My suspicion is that the LINKER is unable to find the source file implementation for the headers.
    How can a import a class which has a ui into my project (preferebly the same way you include e.g QWidget)

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to Implement old ui into new project?

    Your linker errors are telling you that the linker can't find the object code for your ColorPicker class. Using a class in another project means more than just including the header file. The linker needs to be able to find the implementation of the class as well.

    You either 1) add the cpp file to your new project or 2) make a library that contains the classes that you want to re-use and link that to your new projects.

  3. #3
    Join Date
    Jul 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to Implement old ui into new project?

    Thank you very much kind stranger.
    Worked flawlessly.

Similar Threads

  1. Replies: 7
    Last Post: 28th November 2014, 15:59
  2. Replies: 4
    Last Post: 20th January 2013, 11:01
  3. Qt Project to implement Qt Creator's SideBar (FrancyTabBar)
    By xboxnissan in forum Qt Programming
    Replies: 10
    Last Post: 28th December 2011, 06:55
  4. How to convert QT Project to CMake project?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 29th March 2011, 09:48
  5. Replies: 1
    Last Post: 3rd December 2009, 23:34

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.