Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################################################################
- ############################# main.cpp ##################################
- #########################################################################
- #include <QApplication>
- #include <QMessageBox>
- #include <QDebug>
- #include "SlotPrinter.h"
- //#define STANDARD_BUTTONS
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- SlotPrinter oSlotPrinter;
- QMessageBox oMessageBox;
- oMessageBox.setText( "Test message box..." );
- #ifdef STANDARD_BUTTONS
- oMessageBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel );
- #else
- oMessageBox.addButton( "Accept", QMessageBox::AcceptRole );
- oMessageBox.addButton( "Reject", QMessageBox::RejectRole );
- #endif
- if( !QObject::connect( &oMessageBox, SIGNAL(accepted()), &oSlotPrinter, SLOT(SL_PrintAccepted()) ) )
- {
- qWarning() << "Cannot connect SL_PrintAccepted()!";
- }
- if( !QObject::connect( &oMessageBox, SIGNAL(rejected()), &oSlotPrinter, SLOT(SL_PrintRejected()) ) )
- {
- qWarning() << "Cannot connect SL_PrintRejected()!";
- }
- if( !QObject::connect( &oMessageBox, SIGNAL(buttonClicked(QAbstractButton*)),
- &oSlotPrinter, SLOT(SL_PrintButtonClicked(QAbstractButton*)) ) )
- {
- qWarning() << "Cannot connect SL_PrintButtonClicked()!";
- }
- if( !QObject::connect( &oMessageBox, SIGNAL(finished(int)),
- &oSlotPrinter, SLOT(SL_PrintFinished(int)) ) )
- {
- qWarning() << "Cannot connect SL_PrintFinished()!";
- }
- oMessageBox.show();
- return a.exec();
- }
- #########################################################################
- ######################### SlotPrinter .cpp ##############################
- #########################################################################
- #ifndef SLOTPRINTER_H
- #define SLOTPRINTER_H
- #include <QObject>
- #include <QDebug>
- #include <QAbstractButton>
- class SlotPrinter : public QObject
- {
- Q_OBJECT
- public:
- SlotPrinter() {}
- ~SlotPrinter() {}
- public slots:
- void SL_PrintAccepted() { qDebug() << "Accepted"; }
- void SL_PrintRejected() { qDebug() << "Rejected"; }
- void SL_PrintFinished (int iResult ) { qDebug() << "Finished" << iResult; }
- void SL_PrintButtonClicked ( QAbstractButton* pButton ) { qDebug() << "Button clicked" << pButton->text(); }
- };
- #endif // SLOTPRINTER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement