Dialog UI and heritage
-
The best solution (iMHO) is to define access funtions in DialogInvoiceList
Like SetDate( QDate &) and use those from DialogPurchaseI'm agree with you, but I'm the only dev in this case and I want to access directly if possible, I tried to declare ui in protected but I have some error :)
D:\code\mcercle-trunk\src\dialog\dialogpurchase.cpp:17: error: invalid use of incomplete type 'class Ui::DialogInvoiceList' ui -> dateEdit -> setDate( QDate::currentDate());
and
D:\code\mcercle-trunk\src\dialog\dialoginvoicelist.h:10: error: forward declaration of 'class Ui::DialogInvoiceList' class DialogInvoiceList;
-
the implementation of your function must be in the .cpp file.
so where you call ui -> dateEdit -> setDate( QDate::currentDate());
should be in a .cpp file and not .hIs it in .cpp?
-
@cfdev How did you embed
Ui::DialogInvoiceList
into yourDialogInvoiceList
? In your example the ui-class is nowhere!Anyways, if you wanted to create a hierarchy of classes that derive from your ui-class, then the logical thing I'd do:
namespace Ui { class DialogInvoiceList; } class DialogInvoiceList: protected DialogInvoiceList, public QDialog { Q_OBJECT public: explicit DialogInvoiceList(QWidget* parent) : QDialog(parent) { setupUi(this); } } class DialogPurchase : protected DialogInvoiceList { Q_OBJECT public: explicit DialogPurchase(QWidget* parent) : DialogInvoiceList(parent) {} }
I haven't tested, but I'm almost certain you can now access anything in the ui class directly, i.e. a member
checkbox
can be accessed directly in theDialogPurchase
class. -
@Jakob If I use this code, I've some error 'inaccessible' :
D:\code\qt\4.8.7\src\gui\dialogs\qdialog.h:90: error: 'void QDialog::setModal(bool)' is inaccessible void setModal(bool modal);
D:\code\mcercle-trunk\src\mainwindow.cpp:323: error: 'QDialog' is not an accessible base of 'DialogPurchase'
...PS: What is the markdown code to use the syntax color ?!
-
It's ok like this:
namespace Ui { class DialogInvoiceList; }
class DialogInvoiceList: public QDialog, protected Ui::DialogInvoiceList
{
Q_OBJECT
public:
explicit DialogInvoiceList(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
}
}class DialogPurchase : public DialogInvoiceList
{
Q_OBJECT
public:
explicit DialogPurchase(QWidget* parent)
: DialogInvoiceList(parent)
{}
}Many Thanks ;)
-
@cfdev Aaahhh, of course, that actually rings some bells somewhere in the back of my head. I think I read somewhere that if you use multiple inheritance, the
QObject
-derived class must be the first in the list. This has something to do with the moc compiler I think.You get the syntax highlighted using a single backtick for inline highlighting and backtick plus return for a code block.
-
Hi,
Just a side note, you have now a "Code" button with </> as an icon to help you write code blocks