c++ - Emitting a signal not working properly -
i have class called dosecalibration contains dosecalibration.cpp , dosecalibration.h. class associated separate ui form. on form, when button clicked, signal emitted.
there connection within main window receive signal, doesn't seem working. code following:
dosecalibration.h :
#ifndef dosecalibration_h #define dosecalibration_h #include <qdialog> #include <qdebug> namespace ui { class dosecalibration; } class dosecalibration : public qdialog { q_object public: explicit dosecalibration(qwidget *parent = 0); ~dosecalibration(); double dosefactor; //bool dose; private slots: void on_usecharge_clicked(); void on_usecounts_clicked(); void on_pushbutton_clicked(); // void on_pcsb_valuechanged(); // void on_countssb_valuechanged(); signals: void applydose(); private: ui::dosecalibration *ui; }; #endif // dosecalibration_h
dosecalibration.cpp :
#include "dosecalibration.h" #include "ui_dosecalibration.h" dosecalibration::dosecalibration(qwidget *parent) : qdialog(parent), ui(new ui::dosecalibration) { ui->setupui(this); ui->countssb->setenabled(false); ui->countssb->setvalue(ui->pcsb->value()*100/9.6); } dosecalibration::~dosecalibration() { delete ui; } void dosecalibration::on_usecharge_clicked() { ui->countssb->setenabled(false); ui->pcsb->setenabled(true); } void dosecalibration::on_usecounts_clicked() { ui->pcsb->setenabled(false); ui->countssb->setenabled(true); } void dosecalibration::on_pushbutton_clicked() { if(ui->usecharge->ischecked()){ dosefactor = ui->pcsb->value(); } else if(ui->usecounts->ischecked()){ dosefactor = ui->countssb->value(); } emit applydose(); } //void dosecalibration::on_pcsb_valuechanged() //{ // ui->countssb->setvalue(ui->pcsb->value()*100/9.6); //} //void dosecalibration::on_countssb_valuechanged() //{ // ui->pcsb->setvalue(ui->countssb->value()*9.6/100); //}
and mainwindow.h (only included 'includes' , slots):
#ifndef mainwindow_h #define mainwindow_h #include <afe_variables.h> #include <qmainwindow> #include "fpga/fpga.h" #include "fpga/okfrontpaneldll.h" #include "decoder.h" #include "analysis.h" #include "about.h" #include "logfile.h" #include "graph/graphicsscene.h" #include "graph/graphdialog.h" #include "graph/qcustomplot.h" #include "graph/graphicsview.h" #include "settingsdialog.h" #include "dosecalibration.h" #include <qfiledialog> #include <qprogressbar> #include <qgraphicsscene> #include <qgraphicsrectitem> #include <qgraphicstextitem> #include <qdialog> #include <qdebug> #include <math.h> slots: //dose calibration void initialisegraphsafterdose(); void on_actiondose_calibration_4_triggered(); //void dosecalibrationenabled(); private: //initalisation void onstart(); void allocatememory(); void connectfpga(); bool checkconnection(); ui::mainwindow *ui; okcfrontpanel *xem; fpga *fpga; qprogressbar *progressbar; qtimer *playtimer; logfile *logfiledialog; logfile *logfileanalysis; qstring loadlogfilepath; dosecalibration *dose;
and snippet graphing.cpp, part of main window class:
//connects dose calibration dose = new dosecalibration(this); connect(dose,signal(applydose()),this,slot(initialisegraphsafterdose())); } void mainwindow::initialisegraphsafterdose() { apply_dose = true; initialisegraphs(); qdebug() << apply_dose; }
so applydose()
signal emitted @ push of button in dosecalibration ui. connect
should mean value of apply_dose sent console, nothing displayed.
edit:
placing connect within if
statement determine if connecting confirms indeed working correctly.
//connects dose calibration dose = new dosecalibration(this); if(connect(dose,signal(applydose()),this,slot(initialisegraphsafterdose()))) { qdebug() << "connect worked"; } }
the code above outputs message confirming connect.
any idea?
remove multiple instances of dosecalibration
, or make sure connect each 1 of those, if need multiple instances.
Comments
Post a Comment