OK, es ist ein ganz einfaches Test-Programm (ein einfacher Text-Editor):
main.cpp:
Code: Alles auswählen
#include <QApplication>
#include "form.h"
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
myDialog *dlg = new myDialog;
dlg->show();
return app.exec();
}
dialog.h:
Code: Alles auswählen
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog {
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
protected:
void changeEvent(QEvent *e);
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
dialog.cpp:
Code: Alles auswählen
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
form.h:
Code: Alles auswählen
#ifndef FORM_H
#define FORM_H
#include <QtGui>
#include <QDialog>
#include "ui_dialog.h"
class myDialog : public QDialog {
Q_OBJECT
public:
myDialog();
~myDialog() {}
private:
Ui::Dialog ui;
private slots:
void analyseDialog();
};
#endif
form.cpp:
Code: Alles auswählen
#include "form.h"
myDialog::myDialog (){
ui.setupUi(this);
connect( ui.pushButton, SIGNAL( clicked() ),
this, SLOT(analyseDialog()) );
}
void myDialog::analyseDialog() {
QString str;
if( ui.lineEdit->text().isEmpty())
str.append("Name: keine Angaben\n");
else {
str.append("Name: ");
str.append(ui.lineEdit->text());
str.append("\n");
}
if( ui.spinBox->cleanText().isEmpty())
str.append("Geburtsdatum: keine Angaben\n");
else {
str.append("Geburtsdatum: ");
str.append(ui.spinBox->cleanText());
str.append("\n");
}
if( ui.radioButton->isChecked())
str.append("Geschlecht: weiblich\n");
else
str.append("Geschlecht: männlich\n");
QMessageBox::information(
0, tr("Die Auswertung"), str );
}
ui_dialog.h:
Code: Alles auswählen
/********************************************************************************
** Form generated from reading UI file 'dialogrW4556.ui'
**
** Created: Mon 16. Aug 16:45:29 2010
** by: Qt User Interface Compiler version 4.6.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef DIALOGRW4556_H
#define DIALOGRW4556_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QSpinBox>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Dialog
{
public:
QWidget *layoutWidget;
QVBoxLayout *verticalLayout_2;
QGridLayout *gridLayout;
QLabel *label;
QTextEdit *textEdit;
QLabel *label_2;
QSpinBox *spinBox;
QSpacerItem *verticalSpacer_2;
QGroupBox *groupBox;
QVBoxLayout *verticalLayout;
QRadioButton *radioButton;
QRadioButton *radioButton_2;
QSpacerItem *verticalSpacer;
QHBoxLayout *horizontalLayout;
QSpacerItem *horizontalSpacer;
QPushButton *pushButton;
void setupUi(QDialog *Dialog)
{
if (Dialog->objectName().isEmpty())
Dialog->setObjectName(QString::fromUtf8("Dialog"));
Dialog->resize(600, 400);
layoutWidget = new QWidget(Dialog);
layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
layoutWidget->setGeometry(QRect(30, 10, 543, 391));
verticalLayout_2 = new QVBoxLayout(layoutWidget);
verticalLayout_2->setSpacing(6);
verticalLayout_2->setContentsMargins(11, 11, 11, 11);
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
verticalLayout_2->setContentsMargins(0, 0, 0, 0);
gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
label = new QLabel(layoutWidget);
label->setObjectName(QString::fromUtf8("label"));
gridLayout->addWidget(label, 0, 0, 1, 1);
textEdit = new QTextEdit(layoutWidget);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setEnabled(true);
textEdit->setMaximumSize(QSize(487, 20));
gridLayout->addWidget(textEdit, 0, 1, 1, 1);
label_2 = new QLabel(layoutWidget);
label_2->setObjectName(QString::fromUtf8("label_2"));
gridLayout->addWidget(label_2, 1, 0, 1, 1);
spinBox = new QSpinBox(layoutWidget);
spinBox->setObjectName(QString::fromUtf8("spinBox"));
spinBox->setMinimum(1900);
spinBox->setMaximum(2010);
gridLayout->addWidget(spinBox, 1, 1, 1, 1);
verticalLayout_2->addLayout(gridLayout);
verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_2->addItem(verticalSpacer_2);
groupBox = new QGroupBox(layoutWidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
verticalLayout = new QVBoxLayout(groupBox);
verticalLayout->setSpacing(6);
verticalLayout->setContentsMargins(11, 11, 11, 11);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
radioButton = new QRadioButton(groupBox);
radioButton->setObjectName(QString::fromUtf8("radioButton"));
verticalLayout->addWidget(radioButton);
radioButton_2 = new QRadioButton(groupBox);
radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
verticalLayout->addWidget(radioButton_2);
verticalLayout_2->addWidget(groupBox);
verticalSpacer = new QSpacerItem(20, 800, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_2->addItem(verticalSpacer);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setSpacing(6);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
horizontalSpacer = new QSpacerItem(458, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addItem(horizontalSpacer);
pushButton = new QPushButton(layoutWidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
horizontalLayout->addWidget(pushButton);
verticalLayout_2->addLayout(horizontalLayout);
#ifndef QT_NO_SHORTCUT
label->setBuddy(textEdit);
label_2->setBuddy(spinBox);
#endif // QT_NO_SHORTCUT
QWidget::setTabOrder(textEdit, spinBox);
QWidget::setTabOrder(spinBox, radioButton);
QWidget::setTabOrder(radioButton, radioButton_2);
QWidget::setTabOrder(radioButton_2, pushButton);
retranslateUi(Dialog);
QObject::connect(pushButton, SIGNAL(pressed()), Dialog, SLOT(accept()));
QMetaObject::connectSlotsByName(Dialog);
} // setupUi
void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog", "Name", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("Dialog", "Geburtstag", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("Dialog", "Geschlecht", 0, QApplication::UnicodeUTF8));
radioButton->setText(QApplication::translate("Dialog", "M\303\244nnlich", 0, QApplication::UnicodeUTF8));
radioButton_2->setText(QApplication::translate("Dialog", "Weiblich", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("Dialog", "PushButton", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // DIALOGRW4556_H
Und noch die Projekt-Datei:
Code: Alles auswählen
# -------------------------------------------------
# Project created by QtCreator 2010-08-14T10:42:07
# -------------------------------------------------
TARGET = dialog
TEMPLATE = app
SOURCES += main.cpp \
dialog.cpp \
E:/content/Listings/uiexample/form.cpp
HEADERS += dialog.h \
ui_dialog.h \
form.h
FORMS += dialog.ui
ICh hoffe mal das ist jetzt nicht zu viel Code, aber da ich nciht weiß wo der Fehler leigt kann ich ihn nicht kürzen.
mfg