[gelöst] Nur Tray-Icon: App beendet nach QMessageBox

Alles rund um die Programmierung mit Qt
Antworten
pixelflat
Beiträge: 8
Registriert: 27. Mai 2009 12:26

[gelöst] Nur Tray-Icon: App beendet nach QMessageBox

Beitrag von pixelflat »

Hallo,
ich habe einen QDialog und erstelle ein Tray-Icon mit QSystemTrayIcon. Da ich das Dialog-Fenster erst mal nicht brauche, habe ich in der main.cpp w.show(); auskommentiert:

Code: Alles auswählen

QApplication a(argc, argv);
Dialog w;
//w.show();
return a.exec();
Funktioniert wunderbar, nur wenn ich aus dem Tray (mit QMenu) eine QMessageBox ausgebe, beendet sich das komplette Programm danach einfach.

Code: Alles auswählen

statusAction = new QAction(tr("&Status"), this);
statusAction->setIcon(QIcon(":/dialog-information.png"));
connect(statusAction, SIGNAL(triggered()), this, SLOT(showStatus()));

Code: Alles auswählen

void Dialog::showStatus()
{
    msg("Windows will shut down after the following process ends:\nvlc.exe", "Status");
}

Code: Alles auswählen

void Dialog::msg(QString text, QString title)
{
    // Objekt wird im Konstruktor erstellt
    // this->msgBox = new QMessageBox(this);

    this->msgBox->setText(text);
    this->msgBox->setWindowTitle(title);
    this->msgBox->setIcon(QMessageBox::Information);
    this->msgBox->exec();
}
Lasse ich den Dialog ( w.show() ) anzeigen, gibts keine Problem. Die MessageBox wird dann auch nicht zentriert angezeigt, also habe ich über den Parent (this) nachgedacht und stattdessen "parent" verwendet. Die MsgBox ist jetzt zentriert, das Programm beendet aber danach immer noch.

Wieso beendet sich das Programm nach der MsgBox?
Gibts eine bessere Methode für ein "Nur-Tray-App"?

Danke

PS: Verwende den QTCreator.
Zuletzt geändert von pixelflat am 15. September 2009 18:15, insgesamt 1-mal geändert.
Christian81
Beiträge: 7319
Registriert: 26. August 2004 14:11
Wohnort: Bremen
Kontaktdaten:

Beitrag von Christian81 »

MfG Christian

'Funktioniert nicht' ist keine Fehlerbeschreibung
pixelflat
Beiträge: 8
Registriert: 27. Mai 2009 12:26

Beitrag von pixelflat »

Fein, fein. Danke. :)
Antworten