Hi, I'm new here, and I'm trying to understood how works signal and slots.
I have:
mainwindow.h
...
signals:
void setMismatchText
(const QString &text
);
...
...
signals:
void setMismatchText(const QString &text);
...
To copy to clipboard, switch view to plain text mode
mainwindows.cpp
...
Dialog* dialog = new Dialog;
connect(this,
SIGNAL(setMismatchText
(QString)),
dialog,
SLOT(getMismatchText
(QString)));
...
this->setEnabled(false);
Dialog *dialog = new Dialog();
dialog->setModal(true);
emit setMismatchText(error);
if(dialog
->exec
() == QDialog::Accepted) msgBox.setText("Accepted!");
else
msgBox.setText("Denied!");
msgBox.exec();
...
...
Dialog* dialog = new Dialog;
connect(this, SIGNAL(setMismatchText(QString)),
dialog, SLOT(getMismatchText(QString)));
...
this->setEnabled(false);
Dialog *dialog = new Dialog();
dialog->setModal(true);
emit setMismatchText(error);
if(dialog->exec() == QDialog::Accepted)
msgBox.setText("Accepted!");
else
msgBox.setText("Denied!");
msgBox.exec();
...
To copy to clipboard, switch view to plain text mode
dialog.h
...
public slots:
void getMismatchText
(const QString &text
);
...
...
public slots:
void getMismatchText(const QString &text);
...
To copy to clipboard, switch view to plain text mode
dialog.cpp
...
void Dialog
::getMismatchText(const QString &text
) {
ui->plainTextEdit->appendPlainText(text);
}
...
...
void Dialog::getMismatchText(const QString &text)
{
ui->plainTextEdit->appendPlainText(text);
}
...
To copy to clipboard, switch view to plain text mode
In Dialog ui I have QPlayTextEdit Object (objectName - plainTextEdit).
When I emit in mainwindow.cpp, the text in Dialog won't change (or append).
Can you help me please what's wrong? Thanks!
edit:
OK, maybe I fix it.
dialog.h:
public:
public:
void setText(const QString &text);
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
Dialog dialog;
dialog.setText(error);
dialog.exec();
Dialog dialog;
dialog.setText(error);
dialog.exec();
To copy to clipboard, switch view to plain text mode
But I'm not sure, if is it correct wayand still I want to know how works signals a slots.
Sorry for wrong thread, please admin, is possible to change it to "Newbie"?
Bookmarks