PDA

View Full Version : show userform in library



Nightfox
1st June 2011, 15:00
I've been looking in the forum to find examples of how to make available a custom userform in a library.

My project consists of a library (mylib) and test project (test) that uses the library. The library has three classes,

Folder
MyDialogPrivate
MyDialog


I want to make MyDialog available to the test project without having to export the ui_mydialog.h which is why I've implemented it using 'Pointer to implementation' idiom.

In my project it's no problem to display the userform when it's called from within the library (see Folder constructer below)

However I'm getting errors (undefined reference to 'MyDialog::MyDialog(QWidget*)' and undefined reference to 'MyDialog::~MyDialog()') when trying to show the form from the test project that uses the library (see Widget::mouseDoubleClickEvent below)

I've pasted in some key code lines below but please also find the whole project attached.

Can anyone figure out why the userform is not available in the test project?

Test project code, Widget.cpp

Widget::Widget(QWidget *parent) : QWidget(parent)
{
folder = new Folder(this) ;
QLabel *lbl = new QLabel(folder->toString() ) ;
QGridLayout *grid = new QGridLayout;
grid->addWidget(lbl);
setLayout(grid);
}

Widget::~Widget()
{
delete folder ;
}

void Widget::mouseDoubleClickEvent(QMouseEvent *)
{
MyDialog d;
if(d.exec() == QDialog::Accepted)
qDebug() << "Dialog was accepted" ;

}

From the library, MyDialog.h

#include "mylib_global.h"
#include <QDialog>

class MyDialogPrivate;
class MYLIB_EXPORT MyDialog : public QDialog
{
Q_OBJECT

public:
explicit MyDialog(QWidget *parent = 0);
~MyDialog();

private:
MyDialogPrivate *d;
};

MyDialog.cpp

class MyDialogPrivate : public QDialog , public Ui::MyDialog
{
Q_OBJECT

public:
explicit MyDialogPrivate(QWidget *parent = 0) : QDialog(parent) { setupUi(this); }
~MyDialogPrivate(){}
};


MyDialog::MyDialog(QWidget *parent) : QDialog(parent) , d( new MyDialogPrivate(this) )
{
d->setupUi(this);
setWindowTitle("MyDialog");
}

MyDialog::~MyDialog()
{
delete d;
}

Folder implementation

#include "folder.h"
#include "mydialog.h"

Folder::Folder(QObject *parent) : QObject(parent)
{
MyDialog d;
m_str = "Dialog was NOT accepted" ;
if(d.exec() == QDialog::Accepted)
m_str = "Dialog was accepted" ;
}

joyer83
1st June 2011, 17:07
Looks like there are libmylib.so files in the test folder, maybe the test project tries to load them? Shouldn't it load them from mylib-folder?

Nightfox
1st June 2011, 18:24
Yes, the project loads the library from the lib folder as it should say in the LD_LIBRARY_PATH under environment variables