First of all, thanks for your help. I tryed editing the code following your guide lines.

This is new mywidget_p.h

Qt Code:
  1. #ifndef MYWIDGET_P_H
  2. #define MYWIDGET_P_H
  3.  
  4. #include <QWidget>
  5.  
  6. #include "mywidget.h"
  7.  
  8. class MyWidgetPrivate
  9. {
  10. MyWidget * const q; // not stricly necessary, just in case you put methods into MyWidgetPrivate that need access to MyWidget
  11.  
  12. public:
  13. explicit MyWidgetPrivate( MyWidget *parent ) : q( parent ), ui( new Ui::MyWidget )
  14. {
  15. ui->setupUi( parent );
  16. }
  17.  
  18. Ui::MyWidget *ui;
  19.  
  20. QString first;
  21. QString second;
  22. };
  23.  
  24. #endif // MYWIDGET_P_H
To copy to clipboard, switch view to plain text mode 

and this is mywidget.h
Qt Code:
  1. #ifndef MYWIDGET_H
  2. #define MYWIDGET_H
  3.  
  4. #include <QWidget>
  5.  
  6. namespace Ui {
  7. class MyWidget;
  8. }
  9.  
  10. class MyWidgetPrivate;
  11.  
  12. class MyWidget : public QWidget
  13. {
  14. Q_OBJECT
  15. Q_PROPERTY(QString first READ first WRITE setFirst)
  16. Q_PROPERTY(QString second READ second WRITE setSecond)
  17.  
  18. public:
  19. explicit MyWidget(const QString &first,
  20. const QString &second,
  21. QWidget *parent = 0);
  22. ~MyWidget();
  23.  
  24. QString first() const;
  25. void setFirst(const QString);
  26. QString second() const;
  27. void setSecond(const QString);
  28.  
  29. private:
  30. MyWidgetPrivate * const d;
  31. };
  32.  
  33. #endif // MYWIDGET_H
To copy to clipboard, switch view to plain text mode 

Unfortunately the compiler fails

Qt Code:
  1. In file included from ../mywidget.cpp:1:0:
  2. ../mywidget_p.h: In constructor 'MyWidgetPrivate::MyWidgetPrivate(MyWidget*)':
  3. ../mywidget_p.h:13:77: error: invalid use of incomplete type 'class Ui::MyWidget'
  4. In file included from ../mywidget_p.h:6:0,
  5. from ../mywidget.cpp:1:
  6. ../mywidget.h:7:7: error: forward declaration of 'class Ui::MyWidget'
  7. In file included from ../mywidget.cpp:1:0:
  8. ../mywidget_p.h:15:15: error: invalid use of incomplete type 'class Ui::MyWidget'
  9. In file included from ../mywidget_p.h:6:0,
  10. from ../mywidget.cpp:1:
  11. ../mywidget.h:7:7: error: forward declaration of 'class Ui::MyWidget'
  12. ../mywidget.cpp: At global scope:
  13. ../mywidget.cpp:4:1: warning: unused parameter 'first' [-Wunused-parameter]
  14. ../mywidget.cpp:4:1: warning: unused parameter 'second' [-Wunused-parameter]
  15. In file included from /usr/include/QtGui/QWidget:1:0,
  16. from ../mywidget_p.h:4,
  17. from ../mywidget.cpp:1:
  18. /usr/include/QtGui/qwidget.h: In member function 'QString MyWidget::first() const':
  19. /usr/include/QtGui/qwidget.h:150:5: error: 'const QWidgetPrivate* QWidget::d_func() const' is private
  20. ../mywidget.cpp:17:5: error: within this context
  21. ../mywidget.cpp:17:5: error: cannot convert 'const QWidgetPrivate*' to 'const MyWidgetPrivate* const' in initialization
  22. In file included from /usr/include/QtGui/QWidget:1:0,
  23. from ../mywidget_p.h:4,
  24. from ../mywidget.cpp:1:
  25. /usr/include/QtGui/qwidget.h: In member function 'void MyWidget::setFirst(QString)':
  26. /usr/include/QtGui/qwidget.h:150:5: error: 'QWidgetPrivate* QWidget::d_func()' is private
  27. ../mywidget.cpp:23:5: error: within this context
  28. ../mywidget.cpp:23:5: error: cannot convert 'QWidgetPrivate*' to 'MyWidgetPrivate* const' in initialization
  29. In file included from /usr/include/QtGui/QWidget:1:0,
  30. from ../mywidget_p.h:4,
  31. from ../mywidget.cpp:1:
  32. /usr/include/QtGui/qwidget.h: In member function 'QString MyWidget::second() const':
  33. /usr/include/QtGui/qwidget.h:150:5: error: 'const QWidgetPrivate* QWidget::d_func() const' is private
  34. ../mywidget.cpp:29:5: error: within this context
  35. ../mywidget.cpp:29:5: error: cannot convert 'const QWidgetPrivate*' to 'const MyWidgetPrivate* const' in initialization
  36. In file included from /usr/include/QtGui/QWidget:1:0,
  37. from ../mywidget_p.h:4,
  38. from ../mywidget.cpp:1:
  39. /usr/include/QtGui/qwidget.h: In member function 'void MyWidget::setSecond(QString)':
  40. /usr/include/QtGui/qwidget.h:150:5: error: 'QWidgetPrivate* QWidget::d_func()' is private
  41. ../mywidget.cpp:35:5: error: within this context
  42. ../mywidget.cpp:35:5: error: cannot convert 'QWidgetPrivate*' to 'MyWidgetPrivate* const' in initialization
To copy to clipboard, switch view to plain text mode