main.cpp
Code: Alles auswählen
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
Code: Alles auswählen
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <A.h>
#include <Auswahl.h>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
A *myA;
Auswahl * myAuswahl;
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code: Alles auswählen
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
myA = new A();
myAuswahl = new Auswahl();
setCentralWidget(myAuswahl);
}
MainWindow::~MainWindow()
{
}
auswahl.h
Code: Alles auswählen
#ifndef AUSWAHL_H
#define AUSWAHL_H
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>
class Auswahl : public QWidget
{
Q_OBJECT
public:
Auswahl();
QPushButton *buttonAuswahlKlasseA;
QPushButton *buttonAuswahlBeenden;
QVBoxLayout * layoutAuswahl;
QLabel * labelInfoAuswahl;
};
#endif // AUSWAHL_H
auswahl.cpp
Code: Alles auswählen
#include "auswahl.h"
Auswahl::Auswahl()
{
buttonAuswahlKlasseA = new QPushButton(tr("Auswahl Klasse A"));
buttonAuswahlBeenden = new QPushButton(tr("Beenden"));
connect(buttonAuswahlBeenden, SIGNAL(clicked()), this, SLOT(close())); // Beendent Applikation
labelInfoAuswahl = new QLabel(tr("Auswahl Klasse"));
layoutAuswahl = new QVBoxLayout;
layoutAuswahl->addWidget(labelInfoAuswahl);
layoutAuswahl->addWidget(buttonAuswahlKlasseA);
layoutAuswahl->addWidget(buttonAuswahlBeenden);
setLayout(layoutAuswahl);
}
a.h
Code: Alles auswählen
#ifndef A_H
#define A_H
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>
class A : public QWidget
{
Q_OBJECT
public:
A();
QPushButton *buttonFertig;
QVBoxLayout * layoutA;
QLabel * labelInfoA;
};
#endif // A_H
a.cpp
Code: Alles auswählen
#include <QtGui>
#include "a.h"
A::A()
{
buttonFertig = new QPushButton(tr("fetrig"));
connect(buttonFertig, SIGNAL(clicked()), this, SLOT(close()));
labelInfoA = new QLabel(tr("Klasse A"));
layoutA = new QVBoxLayout;
layoutA->addWidget(labelInfoA);
layoutA->addWidget(buttonFertig);
setLayout(layoutA);
}
Hier ist mal der ganze Code. Jetzt habe ich dazu zwei Fragen:
1)
Wie kann ich nun, wenn ich auf den Button buttonAuswahlKlasseA von anwendung.cpp klicke, im mainwindow das Widget a anzeigen lassen? Wie sieht da die Verbindung über connect() aus?
2)
Durch klicken von buttonAuswahlBeenden in auswahl.cpp wird nur das Widget gschlossen. Ist mir auch klar, doch wie bewerkstellige ich es, dass die komplette Anwendung geschlossen wird? Geht das über ein WindowsFlag?
Schon mal Danke für hilfreiche Antworten auf die, für manche hier, gestellten noob-Fragen
LG TK