Heyhey,
i've got some problems trying to add standard actions to a QDialog. I think my code should be right, but it does not work - indicating my code is not right. Does anybody know what i'm doing wrong?
I am starting the Dialog by executing exec(). All I want is to exit the dialog by pressing "OK" or "Cancel". I added a QPushButton for exiting - it works. But it's not what I want. I see the buttons, but they do not emit signals - or I am not able to catch them.
Any ideas?Code://PositionChooser.hpp class PositionChooser : public QDialog { Q_OBJECT private: QWidget* parent; QAction* ok; QAction* cancel; QPushButton p; public: Position getPosition() {return Position();/*posWidget.getPosition();*/} PositionChooser(QWidget* parent); void go(); ~PositionChooser(); public slots: void stopit(); //test slot }; //PositionChooser.cpp PositionChooser::PositionChooser(QWidget* parent_) : parent(parent_), p(this) { //TODO this->setModal(true); //does not work ok = new QAction("OK", this); ok->setSoftKeyRole(QAction::PositiveSoftKey); this->addAction(ok); connect(ok, SIGNAL(triggered()), this, SIGNAL(accept())); //does not work cancel = new QAction("Cancel", this); cancel->setSoftKeyRole(QAction::NegativeSoftKey); this->addAction(cancel); connect(cancel, SIGNAL(triggered()), this, SIGNAL(reject())); //this works p.setText("End"); connect(&p, SIGNAL(pressed()), this, SLOT(accept())); } void PositionChooser::stopit() { //works this->hide(); accept(); //l.setText((std::string("needs to be implemented.\nCode Line ") + Toolbox::toString<int>(__LINE__, 0)).c_str()); } PositionChooser::~PositionChooser() { delete ok; delete cancel; }
Trying to run stopit() instead of accept() or reject() didn't work, either. Qt Version 4.6.2.
Thanks in advance,
Lena




