Header Datei für Qt erstellen???
-
Moin
ich bin ganz neu dabei und habe mal eine Frage ich konnte schon mehrere kleine Programme (in Eclipse) umsetzen wie z.B. HalloQtWelt und folge Programme. Jetzt allerdings habe ich mir dem Qt Designer eine Gui entworfen und will diese benutzen.
Ich Erstelle eine neues Project in Eclipse und verfrachte die *.ui Datei den Ordner. nachdem ich qmake -project und qmake unter Eclipse durchlaufen lasse erstellt mir das Programm eine ui_header Datei.
Jetzt lege ich z.B eine Main.cpp an. Wie gehe ich jetzt weiter vor. Ich finde immer das man eine Header datei noch selber erstellen muß die wiederrum die ui_*.h includet. Kann mir vielleicht mal jemand sagen wie das mit den Aufrufen bzw. mit der selbstgeschriebenen Header Datei funktioniert? Ich habe immer gesehen, dass da die slots oder was das auch ist immer definiert werden müssen. wie z.B diese Zeile
void on_pushButton1_clicked();
über einen Tipp für eine Anleitung die ich noch nicht gefunden habe wäre ich sehr sehr dankbar.
Ach noch was ich habe ein beispiel programm wo die eine main.cpp eine ui_meins.h habe. und halt eine meins.h wo ich keine ahnung habe wie da was rein kommt.
main.cpp
#include <QApplication> #include "meins.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow *window = new MainWindow; window->show(); return app.exec(); }
meins.h (keine ahnung)
#ifndef MEINS_H_ #define MEINS_H_ #include "ui_meins.h" class { Q_OBJECT public: private: }; #endif /*MEINS_H_*/
und die ui_meins.h
#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
bitte bitte ich brauche Hilfe
-
Mein Weg:
ui_Main.h von qmake erstellt*******************************************************************************/ #ifndef UI_MAIN_H #define UI_MAIN_H #include <QtCore/QVariant> //die ganzen Includes //... class Ui_MainWindow { // Der ganze Kram vom Designer // ... }; namespace Ui { class MainWindow: public Ui_MainWindow {}; } // namespace Ui #endif // UI_MAIN_H
Und dann mein eigener Header uimpl_Main.h
#ifndef _UIMPL_MAIN_H_ #define _UIMPL_MAIN_H_ #include "ui_Main.h" class UImplMainWindow // Namensgebung etwas unglücklich, aber was solls.. : public QMainWindow, // "ist ein" QMainWindow private Ui::MainWindow // "wird implementiert durch" Ui::MainWindow { Q_OBJECT public: UImplMainWindow( QWidget* parent = 0 ); public slots: void do_something_good_to_me(); }; #endif
Und dann, die Implementierung von uimpl_Main.h in der gleichnamigen .cpp
#include "uimpl_main.h" UImplMainWindow::UImplMain( QWidget* parent ) : QMainWindow( parent ) { setupUi( this ); // Wichtig! //... // Hier kannst du alles connecten connect( actionMolecular_Mass_Calculation, SIGNAL( triggered() ), this, SLOT( do_something_good_to_me() ) ); } void UImplMain::do_something_good_to_me() { // hey bobby marley... }
-
Ach ja, und die main.cpp
#include <QApplication> #include "uimpl_main.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); UImplMain main_window; main_window.show(); return app.exec(); }