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.
#include "dialog.h"
#include <QApplication>
#include <colorpicker.h>
int main(int argc, char *argv[])
{
Dialog w;
w.show();
ColorPicker picker;
return a.exec();
}
#include "dialog.h"
#include <QApplication>
#include <colorpicker.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
ColorPicker picker;
return a.exec();
}
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:
explicit ColorPicker
(QWidget *parent
= 0);
explicit ColorPicker(QWidget *parent = 0);
To copy to clipboard, switch view to plain text mode
With the following implementation in the source file
ColorPicker
::ColorPicker(QWidget *parent
) : ui(new Ui::ColorPicker)
{
ui->setupUi(this);
Some more code ...
}
ColorPicker::ColorPicker(QWidget *parent) :
QWidget(parent),
ui(new Ui::ColorPicker)
{
ui->setupUi(this);
Some more code ...
}
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)
Bookmarks