Dialog UI and heritage
-
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