Advertisement
Guest User

QMessageBox Example

a guest
Oct 17th, 2012
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #########################################################################
  2. ############################# main.cpp ##################################
  3. #########################################################################
  4.  
  5. #include <QApplication>
  6. #include <QMessageBox>
  7. #include <QDebug>
  8. #include "SlotPrinter.h"
  9.  
  10. //#define STANDARD_BUTTONS
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     QApplication a(argc, argv);
  15.  
  16.     SlotPrinter oSlotPrinter;
  17.  
  18.     QMessageBox oMessageBox;
  19.     oMessageBox.setText( "Test message box..." );
  20. #ifdef STANDARD_BUTTONS
  21.     oMessageBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
  22. #else
  23.     oMessageBox.addButton( "Accept", QMessageBox::AcceptRole );
  24.     oMessageBox.addButton( "Reject", QMessageBox::RejectRole );
  25. #endif
  26.  
  27.     if( !QObject::connect( &oMessageBox, SIGNAL(accepted()), &oSlotPrinter, SLOT(SL_PrintAccepted()) ) )
  28.     {
  29.         qWarning() << "Cannot connect SL_PrintAccepted()!";
  30.     }
  31.     if( !QObject::connect( &oMessageBox, SIGNAL(rejected()), &oSlotPrinter, SLOT(SL_PrintRejected()) ) )
  32.     {
  33.         qWarning() << "Cannot connect SL_PrintRejected()!";
  34.     }
  35.     if( !QObject::connect( &oMessageBox, SIGNAL(buttonClicked(QAbstractButton*)),
  36.                            &oSlotPrinter, SLOT(SL_PrintButtonClicked(QAbstractButton*)) ) )
  37.     {
  38.         qWarning() << "Cannot connect SL_PrintButtonClicked()!";
  39.     }
  40.     if( !QObject::connect( &oMessageBox, SIGNAL(finished(int)),
  41.                            &oSlotPrinter, SLOT(SL_PrintFinished(int)) ) )
  42.     {
  43.         qWarning() << "Cannot connect SL_PrintFinished()!";
  44.     }
  45.  
  46.     oMessageBox.show();
  47.  
  48.  
  49.     return a.exec();
  50. }
  51.  
  52.  
  53. #########################################################################
  54. ######################### SlotPrinter .cpp ##############################
  55. #########################################################################
  56.  
  57. #ifndef SLOTPRINTER_H
  58. #define SLOTPRINTER_H
  59.  
  60. #include <QObject>
  61. #include <QDebug>
  62. #include <QAbstractButton>
  63.  
  64. class SlotPrinter : public QObject
  65. {
  66.     Q_OBJECT
  67.  
  68. public:
  69.     SlotPrinter() {}
  70.     ~SlotPrinter() {}
  71.  
  72. public slots:
  73.     void SL_PrintAccepted() { qDebug() << "Accepted"; }
  74.     void SL_PrintRejected() { qDebug() << "Rejected"; }
  75.     void SL_PrintFinished (int iResult ) { qDebug() << "Finished" << iResult; }
  76.     void SL_PrintButtonClicked ( QAbstractButton* pButton ) { qDebug() << "Button clicked" << pButton->text(); }
  77. };
  78.  
  79. #endif // SLOTPRINTER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement