Seite 1 von 1

dialog aus program raus öffnen

Verfasst: 17. September 2008 15:59
von mcfloppy
Hallo,
habe eine Anwendung, bei der ich ein Fenster öffnen möchte, welches eine qtdesigner-designde Oberfläche hat. Habe nun die ui_x.h. x.cpp sowie x.h angelegt, jedoch funktioniert das alles nicht so recht.


ui_aufgabenneu.h

Code: Alles auswählen

/********************************************************************************
** Form generated from reading ui file 'aufgabenneu.ui'
**
** Created: Wed 17. Sep 13:58:52 2008
**      by: Qt User Interface Compiler version 4.4.1
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/

#ifndef UI_AUFGABENNEU_H
#define UI_AUFGABENNEU_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QPushButton>

QT_BEGIN_NAMESPACE

class Ui_Dialog
{
public:
    QPushButton *pushButton;

    void setupUi(QDialog *Dialog)
    {
    if (Dialog->objectName().isEmpty())
        Dialog->setObjectName(QString::fromUtf8("Dialog"));
    Dialog->resize(400, 300);
    pushButton = new QPushButton(Dialog);
    pushButton->setObjectName(QString::fromUtf8("pushButton"));
    pushButton->setGeometry(QRect(90, 130, 75, 23));

    retranslateUi(Dialog);

    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));
    Q_UNUSED(Dialog);
    } // retranslateUi

};

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

QT_END_NAMESPACE

#endif // UI_AUFGABENNEU_H
aufgabeneu.h:

Code: Alles auswählen

/*
 * aufgabeneu.h
 *
 *  Created on: 17.09.2008
 *      Author: mcfloppy
 */

#ifndef AUFGABENEU_H_
#define AUFGABENEU_H_

#include "ui_aufgabenneu.h"
 class aufgabenneu : public QWidget
 {
     Q_OBJECT

 public:
     aufgabenneu(QWidget *parent = 0);
/*
 private slots:
     void on_inputSpinBox1_valueChanged(int value);
     void on_inputSpinBox2_valueChanged(int value);*/
 private:
     Ui::Dialog ui;

 };

#endif /* AUFGABENEU_H_ */
aufgabeneu.cpp:

Code: Alles auswählen

/*
 * aufgabeneu.cpp
 *
 *  Created on: 17.09.2008
 *      Author: mcfloppy
 */

#include "aufgabeneu.h"

aufgabenneu::aufgabenneu(QWidget *parent) :
	QWidget(parent) {
	ui.setupUi(this);
}
Fehlermeldung:

Code: Alles auswählen

aufgabeneu.cpp: In constructor `aufgabenneu::aufgabenneu(QWidget*)':
aufgabeneu.cpp:12: error: no matching function for call to `Ui::Dialog::setupUi(aufgabenneu* const)'
ui_aufgabenneu.h:28: note: candidates are: void Ui_Dialog::setupUi(QDialog*)
mingw32-make[1]: *** [debug/aufgabeneu.o] Error 1
mingw32-make[1]: Leaving directory `C:/Dokumente und Einstellungen/mcfloppy/workspace/test004_filetool'
mingw32-make: *** [debug] Error 2
Könnt ihr mir weiterhelfen?

Verfasst: 17. September 2008 16:25
von Christian81
setupUI braucht einen QDialog, kein QWidget. Du hast im Designer ein Dialog-Layout erzeugt, also musst Du es auch mit einem QDialog initialisieren.

Verfasst: 17. September 2008 19:10
von mcfloppy
So, der Dialog öffnet nun ohne Fehler :) Problem an der Sache ist, ich kann ihn erst bedienen wenn das Hauptfenster geschlossen wird.
Was mache ich falsch?

hier mein Aufruf:

Code: Alles auswählen

	dialog = new aufgabenneu();
	dialog->show();
	dialog->raise();

Verfasst: 17. September 2008 19:33
von mcfloppy
so, Problem gelöst, war bei den Beispielen spicken.

Neuer Aufruf:

Code: Alles auswählen

	aufgabenneu dialog;
	dialog.exec();