Seite 1 von 1

Warum wird die QMessageBox nicht gezeigt?

Verfasst: 16. Oktober 2006 08:38
von joebar
Hallo,

ich habe ein 08/15 Program und bei klicken auf den OK Button moechte ich eine QMessageBox bekommen. Ich sehe dass die Methode des klickens ausgefuehrt wird. Aber, die QMessageBox wird nicht angezeigt und das Program wird sofort beendet (sprich es koennte auch sein, dass die QMessageBox fuer einen Bruchteil einer Sekunde angezeigt wird). Hat jemand eine Idee?

Und hier das Coding:

testapp.cpp

Code: Alles auswählen

#include "testapp.h"

#include <iostream>
#include <QtGui>
#include <QtCore>

using namespace std;

TestApp::TestApp(QDialog *parent) : QDialog(parent)
{
setupUi(this);
connect(okButton, SIGNAL (clicked()), this, SLOT(slotClose()));

}

TestApp::~TestApp()
{}

void TestApp::slotClose()
{
cout << "Diesen Text sehe ich auf der Konsole";
QMessageBox::information( this, "Titel", "Text", QMessageBox::Ok);
}
Das Headerfile sieht so aus:

Code: Alles auswählen

#ifndef TESTAPP_H
#define TESTAPP_H

#include "ui_testapp.h"

#include <QtGui>
#include <QtCore>

class TestApp : public QDialog, public Ui::TestApp{
Q_OBJECT

public:
	TestApp (QDialog *parent = 0);
	~TestApp();
private slots:
	void slotClose();
};

#endif //TESTAPP_H
Und das Main Programm:

Code: Alles auswählen

#include <QtCore>
#include <QtGui>
#include "testapp.h"

int main( int argc, char* argv[]){

QApplication a(argc, argv);
TestApp w;
w.show();
QObject::connect(&a, SIGNAL(lastWindowClosed()),&a, SLOT(quit()));
return a.exec();


}
Danke,
J.

Verfasst: 16. Oktober 2006 09:08
von BartSimpson
public Ui::TestApp sollte besser private sein.

Re: Warum wird die QMessageBox nicht gezeigt?

Verfasst: 16. Oktober 2006 09:24
von ChMaster
joebar hat geschrieben:Hallo,

ich habe ein 08/15 Program und bei klicken auf den OK Button moechte ich eine QMessageBox bekommen. Ich sehe dass die Methode des klickens ausgefuehrt wird. Aber, die QMessageBox wird nicht angezeigt und das Program wird sofort beendet (sprich es koennte auch sein, dass die QMessageBox fuer einen Bruchteil einer Sekunde angezeigt wird). Hat jemand eine Idee?

Und hier das Coding:

testapp.cpp

Code: Alles auswählen

#include "testapp.h"

// #include <iostream> // auskommentiert, da du Qt benutzt ;)
#include <QtGui>
#include <QtCore> // hier ist auch qDebug() enthalten

// using namespace std; // nicht zwingend notwendig

TestApp::TestApp(QDialog *parent) : QDialog(parent)
{
setupUi(this);
connect(okButton, SIGNAL (clicked()), this, SLOT(slotClose()));

}

TestApp::~TestApp()
{}

void TestApp::slotClose()
{
// cout << "Diesen Text sehe ich auf der Konsole";
qDebug() << "Diesen Text sehe ich auf der Konsole";

// QMessageBox::information( this, "Titel", "Text", QMessageBox::Ok);
QMessageBox::information( this, "Titel", "Text");
}
sollte so aussehen: QMessageBox::information( this, "Titel", "Text");

da du den static member 'information' von der
QMessageBox nutzt brauchst du als dritten param nichts angeben,
da dies automatisch erledigt wird.

wenn du schon Qt benutzt, includier auch QDebug , bzw benutz:
qDebug() << "Diesen Text sehe ich auf der Konsole";
und nicht: cout << "Diesen Text sehe ich auf der Konsole";

siehe code
BartSimpson hat geschrieben: public Ui::TestApp sollte besser private sein.
das kann sein das man es private halten soll, aber in manchen fällen
braucht man eben public ;)

Re: Warum wird die QMessageBox nicht gezeigt?

Verfasst: 16. Oktober 2006 18:56
von joebar
ChMaster hat geschrieben:

sollte so aussehen: QMessageBox::information( this, "Titel", "Text");

da du den static member 'information' von der
QMessageBox nutzt brauchst du als dritten param nichts angeben,
da dies automatisch erledigt wird.
Habe ich geaendert, der Effekt ist der gleiche. Noch andere Ideen?

Danke,
J.

Verfasst: 16. Oktober 2006 20:00
von joebar
Fehler gefunden.

Ich hatte meinen manuellen Slot/Signal und noch den default aus dem Designer.... die Box wurde also angezeigt aber dann sofort das Fenster geschlossen.

Danke, J.