Hi everybody..
I have for examples 2 classes (2 Dialogs). My example send a text from a dialog to the other one. It Works.
But my Question is if my way are correct? Can somebody show me how the professional way works and what is not ok on my example?
my function sendString() are sending a text to the other dialog..
Thanks forwading
main.cpp
//Vorlage für Dialoge
//Klassen:
#include "mydialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MyDialog mydialog;
mydialog.show();
return app.exec();
}
//Vorlage für Dialoge
//Klassen:
#include "mydialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyDialog mydialog;
mydialog.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
mydialog.h
#include "ui_dialog.h"
//My Dialog ist eine Vererbte Klasse von UI_Dialog
{
Q_OBJECT
public:
Ui::Dialog ui;
//Funktionen
public slots:
void showMessage();
void showDialogSuchen();
private:
//Ui::<Name des Objekts, siehe Designer> ui
};
#include "ui_dialog.h"
//My Dialog ist eine Vererbte Klasse von UI_Dialog
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyDialog(QWidget *parent = 0);
Ui::Dialog ui;
//Funktionen
public slots:
void showMessage();
void showDialogSuchen();
private:
//Ui::<Name des Objekts, siehe Designer> ui
};
To copy to clipboard, switch view to plain text mode
mydialog.cpp
//Klassen:
#include "mydialog.h"
#include "dialogsuchen.h"
#include <QMessageBox>
//Konstruktor
MyDialog
::MyDialog(QWidget *parent
) {
ui.setupUi(this);
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(showMessage()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui.openButton, SIGNAL(clicked()), this, SLOT(showDialogSuchen()));
}
//Diese Funktion zeigt eine MessageBox an
void MyDialog::showMessage()
{
"Hallo Welt\n"
"Tutorial 1");
}
void MyDialog::showDialogSuchen()
{
DialogSuchen dialogsuchen(this);
dialogsuchen.exec();
}
//Klassen:
#include "mydialog.h"
#include "dialogsuchen.h"
#include <QMessageBox>
//Konstruktor
MyDialog::MyDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(showMessage()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui.openButton, SIGNAL(clicked()), this, SLOT(showDialogSuchen()));
}
//Diese Funktion zeigt eine MessageBox an
void MyDialog::showMessage()
{
QMessageBox::information(this, "Application name",
"Hallo Welt\n"
"Tutorial 1");
}
void MyDialog::showDialogSuchen()
{
DialogSuchen dialogsuchen(this);
dialogsuchen.exec();
}
To copy to clipboard, switch view to plain text mode
dialogsuchen.h
#include "ui_dialogsuchen.h"
//My Dialog ist eine Vererbte Klasse von UI_Dialog
class DialogSuchen
: public QDialog {
Q_OBJECT
public:
//Funktionen
public slots:
void showMessage();
void sendString();
private:
//Ui::<Name des Objekts, siehe Designer> ui
Ui::DialogSuchen ui;
};
#include "ui_dialogsuchen.h"
//My Dialog ist eine Vererbte Klasse von UI_Dialog
class DialogSuchen : public QDialog
{
Q_OBJECT
public:
DialogSuchen(QWidget *parent = 0);
//Funktionen
public slots:
void showMessage();
void sendString();
private:
//Ui::<Name des Objekts, siehe Designer> ui
Ui::DialogSuchen ui;
};
To copy to clipboard, switch view to plain text mode
dialogsuchen.cpp
//Klassen:
#include "dialogsuchen.h"
#include "mydialog.h"
#include <QMessageBox>
//Konstruktor
DialogSuchen
::DialogSuchen(QWidget *parent
) {
ui.setupUi(this);
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(showMessage()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui.sendButton, SIGNAL(clicked()), this, SLOT(sendString()));
}
//Diese Funktion zeigt eine MessageBox an
void DialogSuchen::showMessage()
{
"Hallo Welt\n"
"Tutorial 1");
}
void DialogSuchen::sendString()
{
MyDialog *mydialog = qobject_cast<MyDialog*>(parent());
QString text
= ui.
lineEdit->text
();
mydialog->ui.textEdit->setPlainText(text);
}
//Klassen:
#include "dialogsuchen.h"
#include "mydialog.h"
#include <QMessageBox>
//Konstruktor
DialogSuchen::DialogSuchen(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(showMessage()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui.sendButton, SIGNAL(clicked()), this, SLOT(sendString()));
}
//Diese Funktion zeigt eine MessageBox an
void DialogSuchen::showMessage()
{
QMessageBox::information(this, "Application name",
"Hallo Welt\n"
"Tutorial 1");
}
void DialogSuchen::sendString()
{
MyDialog *mydialog = qobject_cast<MyDialog*>(parent());
QString text = ui.lineEdit->text();
mydialog->ui.textEdit->setPlainText(text);
}
To copy to clipboard, switch view to plain text mode
Bookmarks