c++ - QTWidget displays twice on just one click -
i have qdialog following:

and 1 gets triggered when click "ok" without selecting image , classifier files both, here

i have linked browse... buttons qfiledialog. now, when click on browse image button, opens file dialog, when select file , press ok, reopens it. same thing happens other browse button , dialog containing label.
any idea, why happening 2 times when event has occurred once?
here slots:
void mysecondqtproject::on_pushimage_clicked() { image = qfiledialog::getopenfilename(this, tr("open file"), "c:/users/mankum93/documents/visual studio 2013/projects/bananaclassifieropencv/bananaclassifieropencv", "images (*.png *.xpm *.jpg)"); } void mysecondqtproject::on_pushclassifier_clicked() { classifier = qfiledialog::getopenfilename(this, tr("open file"), "c:/users/mankum93/documents/visual studio 2013/projects/bananaclassifieropencv/bananaclassifieropencv", "xml files (*.xml)"); } void mysecondqtproject::on_pushok_clicked() { accept(); //now lets compare invalidity of string: if (image.isnull() || classifier.isnull()) { showerrordialog dialog(this); dialog.exec(); } else { //convert qstring std::string string imagefilename = image.tolocal8bit().constdata(); string cascadefilename = classifier.tolocal8bit().constdata(); // now, can go main detection logic detectobject(imagefilename, cascadefilename); } } ps: newbie qt
edit 1: meta object code
void mysecondqtproject::qt_static_metacall(qobject *_o, qmetaobject::call _c, int _id, void **_a) { if (_c == qmetaobject::invokemetamethod) { mysecondqtproject *_t = static_cast<mysecondqtproject *>(_o); switch (_id) { case 0: _t->on_pushimage_clicked(); break; case 1: _t->on_pushclassifier_clicked(); break; case 2: _t->on_pushok_clicked(); break; default: ; } } q_unused(_a); } edit2 : code ui files
/******************************************************************************** ** form generated reading ui file 'mysecondqtprojecthp7256.ui' ** ** created by: qt user interface compiler version 5.4.1 ** ** warning! changes made in file lost when recompiling ui file! ********************************************************************************/ #ifndef mysecondqtprojecthp7256_h #define mysecondqtprojecthp7256_h #include <qtcore/qvariant> #include <qtwidgets/qaction> #include <qtwidgets/qapplication> #include <qtwidgets/qbuttongroup> #include <qtwidgets/qdialog> #include <qtwidgets/qheaderview> #include <qtwidgets/qpushbutton> #include <qtwidgets/qvboxlayout> #include <qtwidgets/qwidget> qt_begin_namespace class ui_mysecondqtprojectclass { public: qpushbutton *pushok; qwidget *layoutwidget; qvboxlayout *verticallayout; qpushbutton *pushimage; qpushbutton *pushclassifier; void setupui(qdialog *mysecondqtprojectclass) { if (mysecondqtprojectclass->objectname().isempty()) mysecondqtprojectclass->setobjectname(qstringliteral("mysecondqtprojectclass")); mysecondqtprojectclass->resize(600, 272); pushok = new qpushbutton(mysecondqtprojectclass); pushok->setobjectname(qstringliteral("pushok")); pushok->setgeometry(qrect(290, 220, 91, 31)); layoutwidget = new qwidget(mysecondqtprojectclass); layoutwidget->setobjectname(qstringliteral("layoutwidget")); layoutwidget->setgeometry(qrect(200, 100, 181, 91)); verticallayout = new qvboxlayout(layoutwidget); verticallayout->setspacing(6); verticallayout->setcontentsmargins(11, 11, 11, 11); verticallayout->setobjectname(qstringliteral("verticallayout")); verticallayout->setcontentsmargins(0, 0, 0, 0); pushimage = new qpushbutton(layoutwidget); pushimage->setobjectname(qstringliteral("pushimage")); verticallayout->addwidget(pushimage); pushclassifier = new qpushbutton(layoutwidget); pushclassifier->setobjectname(qstringliteral("pushclassifier")); verticallayout->addwidget(pushclassifier); retranslateui(mysecondqtprojectclass); qobject::connect(pushimage, signal(clicked()), mysecondqtprojectclass, slot(on_pushimage_clicked())); qobject::connect(pushclassifier, signal(clicked()), mysecondqtprojectclass, slot(on_pushclassifier_clicked())); qobject::connect(pushok, signal(clicked()), mysecondqtprojectclass, slot(on_pushok_clicked())); qmetaobject::connectslotsbyname(mysecondqtprojectclass); } // setupui void retranslateui(qdialog *mysecondqtprojectclass) { mysecondqtprojectclass->setwindowtitle(qapplication::translate("mysecondqtprojectclass", "mysecondqtproject", 0)); pushok->settext(qapplication::translate("mysecondqtprojectclass", "ok", 0)); pushimage->settext(qapplication::translate("mysecondqtprojectclass", "browse image", 0)); pushclassifier->settext(qapplication::translate("mysecondqtprojectclass", "browse classifier", 0)); } // retranslateui }; namespace ui { class mysecondqtprojectclass: public ui_mysecondqtprojectclass {}; } // namespace ui qt_end_namespace #endif // mysecondqtprojecthp7256_h now, code other errordialog:
/******************************************************************************** ** form generated reading ui file 'showerrordialogmu7256.ui' ** ** created by: qt user interface compiler version 5.4.1 ** ** warning! changes made in file lost when recompiling ui file! ********************************************************************************/ #ifndef showerrordialogmu7256_h #define showerrordialogmu7256_h #include <qtcore/qvariant> #include <qtwidgets/qaction> #include <qtwidgets/qapplication> #include <qtwidgets/qbuttongroup> #include <qtwidgets/qdialog> #include <qtwidgets/qheaderview> #include <qtwidgets/qlabel> qt_begin_namespace class ui_showerrordialog { public: qlabel *label; void setupui(qdialog *showerrordialog) { if (showerrordialog->objectname().isempty()) showerrordialog->setobjectname(qstringliteral("showerrordialog")); showerrordialog->resize(400, 65); label = new qlabel(showerrordialog); label->setobjectname(qstringliteral("label")); label->setgeometry(qrect(70, 20, 241, 21)); retranslateui(showerrordialog); qmetaobject::connectslotsbyname(showerrordialog); } // setupui void retranslateui(qdialog *showerrordialog) { showerrordialog->setwindowtitle(qapplication::translate("showerrordialog", "showerrordialog", 0)); label->settext(qapplication::translate("showerrordialog", "please select image or classifier", 0)); } // retranslateui }; namespace ui { class showerrordialog: public ui_showerrordialog {}; } // namespace ui qt_end_namespace #endif // showerrordialogmu7256_h code main cpp file
#include "mysecondqtproject.h" #include "showerrordialog.h" #include <qfiledialog> #include "objectdetect.h" mysecondqtproject::mysecondqtproject(qwidget *parent) : qdialog(parent) { ui.setupui(this); } mysecondqtproject::~mysecondqtproject() { } void mysecondqtproject::on_pushimage_clicked() { image = qfiledialog::getopenfilename(this, tr("open file"), "c:/users/mankum93/documents/visual studio 2013/projects/bananaclassifieropencv/bananaclassifieropencv", "images (*.png *.xpm *.jpg)"); } void mysecondqtproject::on_pushclassifier_clicked() { classifier = qfiledialog::getopenfilename(this, tr("open file"), "c:/users/mankum93/documents/visual studio 2013/projects/bananaclassifieropencv/bananaclassifieropencv", "xml files (*.xml)"); } void mysecondqtproject::on_pushok_clicked() { accept(); //now lets compare invalidity of string: if (image.isnull() || classifier.isnull()) { showerrordialog dialog(this); dialog.exec(); } else { //convert qstring std::string string imagefilename = image.tolocal8bit().constdata(); string cascadefilename = classifier.tolocal8bit().constdata(); // now, can go main detection logic detectobject(imagefilename, cascadefilename); } } edit 3 : here rest of useful files might wanna see
/******************************************************************************** ** form generated reading ui file 'mysecondqtproject.ui' ** ** created by: qt user interface compiler version 5.4.1 ** ** warning! changes made in file lost when recompiling ui file! ********************************************************************************/ #ifndef ui_mysecondqtproject_h #define ui_mysecondqtproject_h #include <qtcore/qvariant> #include <qtwidgets/qaction> #include <qtwidgets/qapplication> #include <qtwidgets/qbuttongroup> #include <qtwidgets/qdialog> #include <qtwidgets/qheaderview> #include <qtwidgets/qpushbutton> #include <qtwidgets/qvboxlayout> #include <qtwidgets/qwidget> qt_begin_namespace class ui_mysecondqtprojectclass { public: qpushbutton *pushok; qwidget *layoutwidget; qvboxlayout *verticallayout; qpushbutton *pushimage; qpushbutton *pushclassifier; void setupui(qdialog *mysecondqtprojectclass) { if (mysecondqtprojectclass->objectname().isempty()) mysecondqtprojectclass->setobjectname(qstringliteral("mysecondqtprojectclass")); mysecondqtprojectclass->resize(600, 272); pushok = new qpushbutton(mysecondqtprojectclass); pushok->setobjectname(qstringliteral("pushok")); pushok->setgeometry(qrect(290, 220, 91, 31)); layoutwidget = new qwidget(mysecondqtprojectclass); layoutwidget->setobjectname(qstringliteral("layoutwidget")); layoutwidget->setgeometry(qrect(200, 100, 181, 91)); verticallayout = new qvboxlayout(layoutwidget); verticallayout->setspacing(6); verticallayout->setcontentsmargins(11, 11, 11, 11); verticallayout->setobjectname(qstringliteral("verticallayout")); verticallayout->setcontentsmargins(0, 0, 0, 0); pushimage = new qpushbutton(layoutwidget); pushimage->setobjectname(qstringliteral("pushimage")); verticallayout->addwidget(pushimage); pushclassifier = new qpushbutton(layoutwidget); pushclassifier->setobjectname(qstringliteral("pushclassifier")); verticallayout->addwidget(pushclassifier); retranslateui(mysecondqtprojectclass); qobject::connect(pushimage, signal(clicked()), mysecondqtprojectclass, slot(on_pushimage_clicked())); qobject::connect(pushclassifier, signal(clicked()), mysecondqtprojectclass, slot(on_pushclassifier_clicked())); qobject::connect(pushok, signal(clicked()), mysecondqtprojectclass, slot(on_pushok_clicked())); qmetaobject::connectslotsbyname(mysecondqtprojectclass); } // setupui void retranslateui(qdialog *mysecondqtprojectclass) { mysecondqtprojectclass->setwindowtitle(qapplication::translate("mysecondqtprojectclass", "mysecondqtproject", 0)); pushok->settext(qapplication::translate("mysecondqtprojectclass", "ok", 0)); pushimage->settext(qapplication::translate("mysecondqtprojectclass", "browse image", 0)); pushclassifier->settext(qapplication::translate("mysecondqtprojectclass", "browse classifier", 0)); } // retranslateui }; namespace ui { class mysecondqtprojectclass: public ui_mysecondqtprojectclass {}; } // namespace ui qt_end_namespace #endif // ui_mysecondqtproject_h and second one:
/******************************************************************************** ** form generated reading ui file 'showerrordialog.ui' ** ** created by: qt user interface compiler version 5.4.1 ** ** warning! changes made in file lost when recompiling ui file! ********************************************************************************/ #ifndef ui_showerrordialog_h #define ui_showerrordialog_h #include <qtcore/qvariant> #include <qtwidgets/qaction> #include <qtwidgets/qapplication> #include <qtwidgets/qbuttongroup> #include <qtwidgets/qdialog> #include <qtwidgets/qheaderview> #include <qtwidgets/qlabel> qt_begin_namespace class ui_showerrordialog { public: qlabel *label; void setupui(qdialog *showerrordialog) { if (showerrordialog->objectname().isempty()) showerrordialog->setobjectname(qstringliteral("showerrordialog")); showerrordialog->resize(400, 65); label = new qlabel(showerrordialog); label->setobjectname(qstringliteral("label")); label->setgeometry(qrect(70, 20, 241, 21)); retranslateui(showerrordialog); qmetaobject::connectslotsbyname(showerrordialog); } // setupui void retranslateui(qdialog *showerrordialog) { showerrordialog->setwindowtitle(qapplication::translate("showerrordialog", "showerrordialog", 0)); label->settext(qapplication::translate("showerrordialog", "please select image or classifier", 0)); } // retranslateui }; namespace ui { class showerrordialog: public ui_showerrordialog {}; } // namespace ui qt_end_namespace #endif // ui_showerrordialog_h
Comments
Post a Comment