First of all, thanks for your help. I tryed editing the code following your guide lines.
This is new mywidget_p.h
#ifndef MYWIDGET_P_H
#define MYWIDGET_P_H
#include <QWidget>
#include "mywidget.h"
class MyWidgetPrivate
{
MyWidget * const q; // not stricly necessary, just in case you put methods into MyWidgetPrivate that need access to MyWidget
public:
explicit MyWidgetPrivate( MyWidget *parent ) : q( parent ), ui( new Ui::MyWidget )
{
ui->setupUi( parent );
}
Ui::MyWidget *ui;
};
#endif // MYWIDGET_P_H
#ifndef MYWIDGET_P_H
#define MYWIDGET_P_H
#include <QWidget>
#include "mywidget.h"
class MyWidgetPrivate
{
MyWidget * const q; // not stricly necessary, just in case you put methods into MyWidgetPrivate that need access to MyWidget
public:
explicit MyWidgetPrivate( MyWidget *parent ) : q( parent ), ui( new Ui::MyWidget )
{
ui->setupUi( parent );
}
Ui::MyWidget *ui;
QString first;
QString second;
};
#endif // MYWIDGET_P_H
To copy to clipboard, switch view to plain text mode
and this is mywidget.h
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
namespace Ui {
class MyWidget;
}
class MyWidgetPrivate;
{
Q_OBJECT
Q_PROPERTY(QString first READ first WRITE setFirst
) Q_PROPERTY(QString second READ second WRITE setSecond
)
public:
explicit MyWidget
(const QString &first,
~MyWidget();
private:
MyWidgetPrivate * const d;
};
#endif // MYWIDGET_H
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
namespace Ui {
class MyWidget;
}
class MyWidgetPrivate;
class MyWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString first READ first WRITE setFirst)
Q_PROPERTY(QString second READ second WRITE setSecond)
public:
explicit MyWidget(const QString &first,
const QString &second,
QWidget *parent = 0);
~MyWidget();
QString first() const;
void setFirst(const QString);
QString second() const;
void setSecond(const QString);
private:
MyWidgetPrivate * const d;
};
#endif // MYWIDGET_H
To copy to clipboard, switch view to plain text mode
Unfortunately the compiler fails
In file included from ../mywidget.cpp:1:0:
../mywidget_p.h: In constructor 'MyWidgetPrivate::MyWidgetPrivate(MyWidget*)':
../mywidget_p.h:13:77: error: invalid use of incomplete type 'class Ui::MyWidget'
In file included from ../mywidget_p.h:6:0,
from ../mywidget.cpp:1:
../mywidget.h:7:7: error: forward declaration of 'class Ui::MyWidget'
In file included from ../mywidget.cpp:1:0:
../mywidget_p.h:15:15: error: invalid use of incomplete type 'class Ui::MyWidget'
In file included from ../mywidget_p.h:6:0,
from ../mywidget.cpp:1:
../mywidget.h:7:7: error: forward declaration of 'class Ui::MyWidget'
../mywidget.cpp: At global scope:
../mywidget.cpp:4:1: warning: unused parameter 'first' [-Wunused-parameter]
../mywidget.cpp:4:1: warning: unused parameter 'second' [-Wunused-parameter]
In
file included from
/usr
/include
/QtGui
/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'QString MyWidget::first() const':
/usr/include/QtGui/qwidget.h:150:5: error: 'const QWidgetPrivate* QWidget::d_func() const' is private
../mywidget.cpp:17:5: error: within this context
../mywidget.cpp:17:5: error: cannot convert 'const QWidgetPrivate*' to 'const MyWidgetPrivate* const' in initialization
In
file included from
/usr
/include
/QtGui
/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'void MyWidget::setFirst(QString)':
/usr/include/QtGui/qwidget.h:150:5: error: 'QWidgetPrivate* QWidget::d_func()' is private
../mywidget.cpp:23:5: error: within this context
../mywidget.cpp:23:5: error: cannot convert 'QWidgetPrivate*' to 'MyWidgetPrivate* const' in initialization
In
file included from
/usr
/include
/QtGui
/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'QString MyWidget::second() const':
/usr/include/QtGui/qwidget.h:150:5: error: 'const QWidgetPrivate* QWidget::d_func() const' is private
../mywidget.cpp:29:5: error: within this context
../mywidget.cpp:29:5: error: cannot convert 'const QWidgetPrivate*' to 'const MyWidgetPrivate* const' in initialization
In
file included from
/usr
/include
/QtGui
/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'void MyWidget::setSecond(QString)':
/usr/include/QtGui/qwidget.h:150:5: error: 'QWidgetPrivate* QWidget::d_func()' is private
../mywidget.cpp:35:5: error: within this context
../mywidget.cpp:35:5: error: cannot convert 'QWidgetPrivate*' to 'MyWidgetPrivate* const' in initialization
In file included from ../mywidget.cpp:1:0:
../mywidget_p.h: In constructor 'MyWidgetPrivate::MyWidgetPrivate(MyWidget*)':
../mywidget_p.h:13:77: error: invalid use of incomplete type 'class Ui::MyWidget'
In file included from ../mywidget_p.h:6:0,
from ../mywidget.cpp:1:
../mywidget.h:7:7: error: forward declaration of 'class Ui::MyWidget'
In file included from ../mywidget.cpp:1:0:
../mywidget_p.h:15:15: error: invalid use of incomplete type 'class Ui::MyWidget'
In file included from ../mywidget_p.h:6:0,
from ../mywidget.cpp:1:
../mywidget.h:7:7: error: forward declaration of 'class Ui::MyWidget'
../mywidget.cpp: At global scope:
../mywidget.cpp:4:1: warning: unused parameter 'first' [-Wunused-parameter]
../mywidget.cpp:4:1: warning: unused parameter 'second' [-Wunused-parameter]
In file included from /usr/include/QtGui/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'QString MyWidget::first() const':
/usr/include/QtGui/qwidget.h:150:5: error: 'const QWidgetPrivate* QWidget::d_func() const' is private
../mywidget.cpp:17:5: error: within this context
../mywidget.cpp:17:5: error: cannot convert 'const QWidgetPrivate*' to 'const MyWidgetPrivate* const' in initialization
In file included from /usr/include/QtGui/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'void MyWidget::setFirst(QString)':
/usr/include/QtGui/qwidget.h:150:5: error: 'QWidgetPrivate* QWidget::d_func()' is private
../mywidget.cpp:23:5: error: within this context
../mywidget.cpp:23:5: error: cannot convert 'QWidgetPrivate*' to 'MyWidgetPrivate* const' in initialization
In file included from /usr/include/QtGui/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'QString MyWidget::second() const':
/usr/include/QtGui/qwidget.h:150:5: error: 'const QWidgetPrivate* QWidget::d_func() const' is private
../mywidget.cpp:29:5: error: within this context
../mywidget.cpp:29:5: error: cannot convert 'const QWidgetPrivate*' to 'const MyWidgetPrivate* const' in initialization
In file included from /usr/include/QtGui/QWidget:1:0,
from ../mywidget_p.h:4,
from ../mywidget.cpp:1:
/usr/include/QtGui/qwidget.h: In member function 'void MyWidget::setSecond(QString)':
/usr/include/QtGui/qwidget.h:150:5: error: 'QWidgetPrivate* QWidget::d_func()' is private
../mywidget.cpp:35:5: error: within this context
../mywidget.cpp:35:5: error: cannot convert 'QWidgetPrivate*' to 'MyWidgetPrivate* const' in initialization
To copy to clipboard, switch view to plain text mode
Bookmarks