Seite 1 von 1

Brauche ganz viel Hilfe

Verfasst: 13. Februar 2007 11:27
von Dschingiskorn
Moin

ich habe mit QT eine Gui entworfen diese unter meins.ui abgespeichert und in einem neuen Projekt eingebunden (Elcipse). In dem Projekt befindet sich sonst noch nichts. Habe qmake -project und qmake (in Eclipse) laufen lassen und ich bekomme eine ui_meins.h das ist ja noch richtig glaube ich so jetzt will ich die GUI natürlich in ein programm einbinden. das habe ich versucht.

main.cpp

Code: Alles auswählen

#include <QApplication>
#include "meins.h"

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     Ui_Dialog *meins = new Ui_Dialog;
     meins->show();
     return app.exec();
}

meins.h

Code: Alles auswählen

#ifndef MEINS_H_
#define MEINS_H_

#include "ui_meins.h"

class Ui_Dialog : public QWidget
{
        Q_OBJECT

public:
    Ui_Dialog(QWidget *parent = 0);

private slots:
    void on_inputSpinBox1_valueChanged(int value);
    void on_inputSpinBox2_valueChanged(int value);

private:
    Ui::Ui_Dialog ui;
};

#endif /*MEINS_H_*/
und die ui_meins.h

Code: Alles auswählen

#ifndef UI_MEINS_H
#define UI_MEINS_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpinBox>
#include <QtGui/QTextEdit>

class Ui_Dialog
{
public:
    QDialogButtonBox *buttonBox;
    QPushButton *pushButton;
    QPushButton *pushButton_2;
    QTextEdit *textEdit;
    QPushButton *pushButton_3;
    QSpinBox *spinBox_2;
    QLineEdit *lineEdit;
    QSpinBox *spinBox;

    void setupUi(QDialog *Dialog)
    {
    Dialog->setObjectName(QString::fromUtf8("Dialog"));
    buttonBox = new QDialogButtonBox(Dialog);
    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
    buttonBox->setGeometry(QRect(30, 240, 341, 32));
    buttonBox->setOrientation(Qt::Horizontal);
    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
    pushButton = new QPushButton(Dialog);
    pushButton->setObjectName(QString::fromUtf8("pushButton"));
    pushButton->setGeometry(QRect(20, 20, 75, 24));
    pushButton_2 = new QPushButton(Dialog);
    pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
    pushButton_2->setGeometry(QRect(20, 60, 75, 24));
    textEdit = new QTextEdit(Dialog);
    textEdit->setObjectName(QString::fromUtf8("textEdit"));
    textEdit->setGeometry(QRect(120, 20, 251, 211));
    pushButton_3 = new QPushButton(Dialog);
    pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
    pushButton_3->setGeometry(QRect(20, 120, 75, 24));
    spinBox_2 = new QSpinBox(Dialog);
    spinBox_2->setObjectName(QString::fromUtf8("spinBox_2"));
    spinBox_2->setGeometry(QRect(70, 190, 46, 22));
    lineEdit = new QLineEdit(Dialog);
    lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    lineEdit->setGeometry(QRect(0, 160, 113, 22));
    spinBox = new QSpinBox(Dialog);
    spinBox->setObjectName(QString::fromUtf8("spinBox"));
    spinBox->setGeometry(QRect(10, 190, 46, 22));

    retranslateUi(Dialog);

    QSize size(400, 300);
    size = size.expandedTo(Dialog->minimumSizeHint());
    Dialog->resize(size);

    QObject::connect(buttonBox, SIGNAL(accepted()), Dialog, SLOT(accept()));
    QObject::connect(buttonBox, SIGNAL(rejected()), Dialog, SLOT(reject()));
    QObject::connect(pushButton, SIGNAL(clicked()), textEdit, SLOT(clear()));
    QObject::connect(pushButton_2, SIGNAL(clicked()), textEdit, SLOT(selectAll()));
    QObject::connect(pushButton_2, SIGNAL(clicked()), textEdit, SLOT(copy()));
    QObject::connect(spinBox, SIGNAL(valueChanged(int)), lineEdit, SLOT(update()));
    QObject::connect(spinBox_2, SIGNAL(valueChanged(int)), lineEdit, SLOT(update()));
    QObject::connect(pushButton_3, SIGNAL(clicked()), lineEdit, SLOT(copy()));
    QObject::connect(pushButton_3, SIGNAL(clicked()), textEdit, SLOT(paste()));

    QMetaObject::connectSlotsByName(Dialog);
    } // setupUi

    void retranslateUi(QDialog *Dialog)
    {
    Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
    pushButton->setText(QApplication::translate("Dialog", "PushButton", 0, QApplication::UnicodeUTF8));
    pushButton_2->setText(QApplication::translate("Dialog", "PushButton", 0, QApplication::UnicodeUTF8));
    pushButton_3->setText(QApplication::translate("Dialog", "PushButton", 0, QApplication::UnicodeUTF8));
    Q_UNUSED(Dialog);
    } // retranslateUi

};

namespace Ui {
    class Dialog: public Ui_Dialog {};
} // namespace Ui

#endif // UI_MEINS_H
mein problem liegt in der main und der meins.h wie muss ich da welche klassen angeben und all das. wie man sieht habe ich es schon versucht (schon viele Versuche) je nach version bekommen ich in der main als Fehler Ui_Dialog hat keine funktion show. oder so was wie

error: expected `;' before "ui".

Bitte ich brauche Hilfe. Es sind ja wirklich nur ein paar zeilen in der main und der meins.h aber ich habe keine Ahnung wo welche klasse hin kommt usw.

Verfasst: 23. Februar 2007 17:28
von horchi
Hi Dschingiskorn,

versuche es einmal so,

meins.h

Code: Alles auswählen

#ifndef MEINS_H_
#define MEINS_H_

#include "ui_meins.h"

class MeinsDialog : public QWidget, private Ui::Dialog
{
        Q_OBJECT

public:
        MeinsDialog(QWidget *parent = 0) ;
    
private slots:
     void on_inputSpinBox1_valueChanged(int value);
     void on_inputSpinBox2_valueChanged(int value);

private:

};
#endif /*MEINS_H_*/
main.cpp

Code: Alles auswählen

#include <QApplication>
#include "meins.h"

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     MeinsDialog *meins = new MeinsDialog;
     meins->show();
     return app.exec();
} 
Dann fehlt natürrlich noch die Implementation von:
MeinsDialog(QWidget *parent = 0) ;
void on_inputSpinBox1_valueChanged(int value);
void on_inputSpinBox2_valueChanged(int value);


horchi

Verfasst: 23. Februar 2007 17:36
von horchi
Sorry eines hatte ich noch übersehen, du musst den Dialog von QDialog und nicht von Widget ableiten, also:

Code: Alles auswählen

#ifndef MEINS_H_
#define MEINS_H_

#include "ui_meins.h"

class MeinsDialog : public QDialog, private Ui::Dialog
{
        Q_OBJECT

public:
        MeinsDialog(QWidget* parent = 0) : QDialog(parent) { setupUi(this); }
        
        

private slots:
//     void on_inputSpinBox1_valueChanged(int value);
//     void on_inputSpinBox2_valueChanged(int value);

private:

};
#endif /*MEINS_H_*/