Portál AbcLinuxu, 28. října 2025 21:46
//protected variables in header file:
QWidget *dialog_err;
QLabel *text;
QDialogButtonBox *button;
QDesktopWidget *desktop;
//////////////////////////////////////////////////////
//cpp file:
#include "DialogErrorClass.h"
DialogErrorClass::DialogErrorClass( QWidget *parent ) : QWidget(parent) {
desktop = QApplication::desktop();
// create window
dialog_err = new QWidget;
dialog_err->setObjectName( QString::fromUtf8( "DialogError" ) );
dialog_err->move( ( ( desktop->width() - 420 ) / 2 ), ( ( desktop->height() - 93 ) / 2 ) );
dialog_err->setWindowTitle( QApplication::translate( "DialogError", "Chyba programu", 0, QApplication::UnicodeUTF8 ) );
//label text error message
text = new QLabel( dialog_err );
text->setObjectName( QString::fromUtf8( "errorMsg" ) );
text->setGeometry( QRect( 10, 10, 400, 21 ) );
text->setStyleSheet(QString::fromUtf8("align: right;"));
// close button
button = new QDialogButtonBox( QDialogButtonBox::Cancel, Qt::Horizontal, dialog_err );
button->setObjectName( QString::fromUtf8( "closeButton" ) );
button->setGeometry( QRect( 169, 51, 81, 32 ) );
}
void DialogErrorClass::setMessage( const char *msg ) {
text->setText( QApplication::translate( "errorMsg", (char*)msg, 0, QApplication::UnicodeUTF8 ) );
}
void DialogErrorClass::show() {
connect( button, SIGNAL( accepted() ), qApp, SLOT( quit() ) );
dialog_err->show();
}
Řešení dotazu:
button obsahuje len tlacidlo QDialogButtonBox::Cancel, ktore emituje len signal rejected (nie accepted).
Toto by uz mohlo fungovat:
connect( button, SIGNAL( rejected() ), qApp, SLOT( quit() ) );
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.