Results 1 to 3 of 3

Thread: show userform in library

  1. #1
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default show userform in library

    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,
    1. Folder
    2. MyDialogPrivate
    3. 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
    Qt Code:
    1. Widget::Widget(QWidget *parent) : QWidget(parent)
    2. {
    3. folder = new Folder(this) ;
    4. QLabel *lbl = new QLabel(folder->toString() ) ;
    5. QGridLayout *grid = new QGridLayout;
    6. grid->addWidget(lbl);
    7. setLayout(grid);
    8. }
    9.  
    10. Widget::~Widget()
    11. {
    12. delete folder ;
    13. }
    14.  
    15. void Widget::mouseDoubleClickEvent(QMouseEvent *)
    16. {
    17. MyDialog d;
    18. if(d.exec() == QDialog::Accepted)
    19. qDebug() << "Dialog was accepted" ;
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    From the library, MyDialog.h
    Qt Code:
    1. #include "mylib_global.h"
    2. #include <QDialog>
    3.  
    4. class MyDialogPrivate;
    5. class MYLIB_EXPORT MyDialog : public QDialog
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. explicit MyDialog(QWidget *parent = 0);
    11. ~MyDialog();
    12.  
    13. private:
    14. MyDialogPrivate *d;
    15. };
    To copy to clipboard, switch view to plain text mode 

    MyDialog.cpp
    Qt Code:
    1. class MyDialogPrivate : public QDialog , public Ui::MyDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MyDialogPrivate(QWidget *parent = 0) : QDialog(parent) { setupUi(this); }
    7. ~MyDialogPrivate(){}
    8. };
    9.  
    10.  
    11. MyDialog::MyDialog(QWidget *parent) : QDialog(parent) , d( new MyDialogPrivate(this) )
    12. {
    13. d->setupUi(this);
    14. setWindowTitle("MyDialog");
    15. }
    16.  
    17. MyDialog::~MyDialog()
    18. {
    19. delete d;
    20. }
    To copy to clipboard, switch view to plain text mode 
    Folder implementation
    Qt Code:
    1. #include "folder.h"
    2. #include "mydialog.h"
    3.  
    4. Folder::Folder(QObject *parent) : QObject(parent)
    5. {
    6. MyDialog d;
    7. m_str = "Dialog was NOT accepted" ;
    8. if(d.exec() == QDialog::Accepted)
    9. m_str = "Dialog was accepted" ;
    10. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: show userform in library

    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?

  3. #3
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: show userform in library

    Yes, the project loads the library from the lib folder as it should say in the LD_LIBRARY_PATH under environment variables

Similar Threads

  1. Replies: 2
    Last Post: 19th February 2011, 11:26
  2. Replies: 5
    Last Post: 25th July 2010, 10:58
  3. Replies: 3
    Last Post: 12th July 2010, 13:12
  4. Replies: 4
    Last Post: 18th December 2009, 18:55

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.