At first I created a Qt4 Gui Application, with Mainwindow.->testprogram
Then I created a Qt Designer Form Class -> dialog2
When I click on the addbutton on the 'testprogram' dialog it opens the 'dialog2' dialog. Some basic code:
testprogram.cpp
void testprogram::addClicked()
{
dialog2 dialog;
if (dialog.
exec() == QDialog::Accepted) {
// here I get the data from dialog2 and put it into an textEdit. .e.g with a plaintext:
QString taskdescrp
= dialog.
adddescription();
ui->textEdit->setPlainText(taskdescrp);
}
else
{
return;
}
}
void testprogram::addClicked()
{
dialog2 dialog;
if (dialog.exec() == QDialog::Accepted)
{
// here I get the data from dialog2 and put it into an textEdit. .e.g with a plaintext:
QString taskdescrp = dialog.adddescription();
ui->textEdit->setPlainText(taskdescrp);
}
else
{
return;
}
}
To copy to clipboard, switch view to plain text mode
dialog2.h
Q_OBJECT
public:
~dialog2();
public slots:
void dialog2_addbuttonClicked();
class dialog2 : public QDialog {
Q_OBJECT
public:
dialog2(QWidget *parent = 0);
~dialog2();
QString adddescription();
public slots:
void dialog2_addbuttonClicked();
To copy to clipboard, switch view to plain text mode
dialog2.cpp
void dialog2::dialog2_addbuttonClicked()
{
QString taskdesc
= m_ui
->dialog2_textEdit
->toPlainText
();
accept();
}
{
return m_ui->dialog2_textEdit->toPlainText();
}
void dialog2::dialog2_addbuttonClicked()
{
QString taskdesc = m_ui->dialog2_textEdit->toPlainText();
accept();
}
QString dialog2::adddescription()
{
return m_ui->dialog2_textEdit->toPlainText();
}
To copy to clipboard, switch view to plain text mode
I just don't know how to do it reverse.
I think i should put something like you suggested into this part of the dialog2.cpp:
dialog2
::dialog2(QWidget *parent
) : m_ui(new Ui::dialog2)
{
m_ui->setupUi(this);
connect(m_ui->dialog2_addButton, SIGNAL(clicked()), this, SLOT(dialog2_addbuttonClicked()));
m_ui->dialog2_lineEdit2->setText(((testprogram*)this->parent())->dateEdit->text());
}
dialog2::dialog2(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::dialog2)
{
m_ui->setupUi(this);
connect(m_ui->dialog2_addButton, SIGNAL(clicked()), this, SLOT(dialog2_addbuttonClicked()));
m_ui->dialog2_lineEdit2->setText(((testprogram*)this->parent())->dateEdit->text());
}
To copy to clipboard, switch view to plain text mode
And I created this in the testprogram.cpp also:
QString testprogram
::adddatestring() {
return ui->lineEdit4->text(); //i want this to be passed to a lineEdit of dialog2
}
QString testprogram::adddatestring()
{
return ui->lineEdit4->text(); //i want this to be passed to a lineEdit of dialog2
}
To copy to clipboard, switch view to plain text mode
I hope you see something...
Bookmarks