Hallo, I'm having difficulties doing something very easy (seemingly)...
MyDialog is a subclass of QDialog
.h
{
Q_OBJECT
public:
explicit MyDialog
(QWidget * parent
= 0);
~MyDialog(){ }
private:
MyOkButton* m_pOkButton; // MyOkButton is derived from QPushButton
MyCancelButton* m_pCancelButton; // MyCancelButton is derived from QPushButton
// =====================================================================================
// SIGNAL / SLOTS
// =====================================================================================
signals:
public slots:
void OnOk_Slot(void);
void OnCancel_Slot(void);
};
class MyDialog : public QDialog
{
Q_OBJECT
public:
explicit MyDialog(QWidget * parent = 0);
~MyDialog(){ }
private:
MyOkButton* m_pOkButton; // MyOkButton is derived from QPushButton
MyCancelButton* m_pCancelButton; // MyCancelButton is derived from QPushButton
QDialogButtonBox* m_pDialogButtonBox;
QVBoxLayout* m_pDialogLayout;
// =====================================================================================
// SIGNAL / SLOTS
// =====================================================================================
signals:
public slots:
void OnOk_Slot(void);
void OnCancel_Slot(void);
};
To copy to clipboard, switch view to plain text mode
.cpp
MyDialog
::MyDialog(QWidget * parent
) :
{
m_pOkButton = new MyOkButton(this);
connect(m_pOkButton, SIGNAL(clicked()), this, SLOT(OnOk_Slot()));
m_pOkButton
->SetHint
(QSize(100,
100));
// SetHint is a method of MyOkButton
m_pCancelButton
= new MyCancelButton
(QSize(),
"",
this);
connect(m_pCancelButton, SIGNAL(clicked()), this, SLOT(OnCancel_Slot()));
m_spCancelButton
->SetHint
(QSize(100,
100));
// SetHint is a method of MyCancelButton
m_pDialogLayout->addWidget(m_spDialogButtonBox);
setLayout(m_spDialogLayout);
}
void MyDialog::OnOk_Slot(void)
{
accept();
}
void MyDialog::OnCancel_Slot(void)
{
reject();
}
MyDialog::MyDialog(QWidget * parent)
:
QDialog(parent)
{
m_pOkButton = new MyOkButton(this);
connect(m_pOkButton, SIGNAL(clicked()), this, SLOT(OnOk_Slot()));
m_pOkButton->SetHint(QSize(100, 100)); // SetHint is a method of MyOkButton
m_pCancelButton = new MyCancelButton(QSize(), "", this);
connect(m_pCancelButton, SIGNAL(clicked()), this, SLOT(OnCancel_Slot()));
m_spCancelButton->SetHint(QSize(100, 100)); // SetHint is a method of MyCancelButton
m_pDialogButtonBox = new QDialogButtonBox(this);
m_pDialogButtonBox->addButton(m_pOkButton, QDialogButtonBox::AcceptRole);
m_pDialogButtonBox->addButton(m_pCancelButton, QDialogButtonBox::RejectRole);
m_pDialogLayout = new QVBoxLayout(this);
m_pDialogLayout->addWidget(m_spDialogButtonBox);
setLayout(m_spDialogLayout);
}
void MyDialog::OnOk_Slot(void)
{
accept();
}
void MyDialog::OnCancel_Slot(void)
{
reject();
}
To copy to clipboard, switch view to plain text mode
In my main window, the slot related to a certain pushbutton click is:
[code]
void MyMainWindow::OnMyButton_slot(bool)
{
MyDialog * l_d = new MyDialog(this);
l_d->setWindowTitle("Title");
l_d->setFixedSize(300, 300);
l_d->exec();
}
[code]
When executing the MyDialog constructor (MyDialog * l_d = new MyDialog(this) in the QT Creator Application Output area appears "Debugging has finished" and the execution stops.
Is it correct to create and "launch" a dialog in the slot related to a certain button pressure or shall I invoke some other method through the QMetaObject?
Is it correct to pass this (pointer to the QMainWindow) to MyDialog, so that its instance is child of the MainWindow?
Are there best practises to subclass QDialog?
Thank you for giving me some help!
Added after 16 minutes:
It's something related to the use of MyOkButton and MyCancelButton as ok/cancel.
If i use the code below everything ok:
m_spDialogButtonBox
->setStandardButtons
(QDialogButtonBox::Cancel|QDialogButtonBox
::Ok);
QObject::connect(m_spDialogButtonBox,
SIGNAL(accepted
()),
this,
SLOT(accept
()));
QObject::connect(m_spDialogButtonBox,
SIGNAL(rejected
()),
this,
SLOT(reject
()));
m_spDialogButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
QObject::connect(m_spDialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
QObject::connect(m_spDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
To copy to clipboard, switch view to plain text mode
Added after 15 minutes:
What shall I do to have customized pushbuttons in my dialog?
Bookmarks