c++ - QSignalMapper does not update parameter after choosing file -


i'm making application able program board. select file via file dialog , upload board selected file upload button. have 2 class it: myfiledialog , commandprocess. connected upload button clicked signal signal mapper , mapped commandprocess::startprocess slot, executes process path of selected file path incorrect if don't indicate on start of program. how can update mapping parameter after choose file?

part of main.cpp code:

qobject *uploadbutton = mainform->findchild<qobject*>("uploadbutton");  qsignalmapper mapper; consoleprocess proc; myfiledialog mfd;  qobject::connect(filebutton, signal(clicked()), &mfd, slot(openmyfiledialog())); qobject::connect(uploadbutton, signal(clicked()), &mapper, slot(map())); mapper.setmapping(uploadbutton, mfd.getfilename()); qobject::connect(&mapper, signal(mapped(const qstring &)),&proc, slot(startprocess(const qstring &)));  

myfiledialog class:

public:     myfiledialog();     qstring getfilename();  private:     qfiledialog fd;   public slots:     void openmyfiledialog();  qstring myfiledialog::getfilename()   {     return fd.getopenfilename(); } 

consoleprocess class:

private:     qprocess p;  public:     consoleprocess();  public slots:     void startprocess(const qstring &);  void consoleprocess::startprocess(const qstring & path) {     p.setworkingdirectory("c:/avrdude");     p.start("cmd.exe /c start avrdude.exe -c breakout -p ft0 -p m2560 -u flash:w:\"" + path + "\":a"); } 

you can create 2 slots @ mainwindow class , qstring member storing path file this:

class mainwindow : public qmainwindow, private ui::mainwindow {     q_object  public:     explicit mainwindow(qwidget *parent = 0);  public slots:     void choseslot();     void uploadslot();  private:     qstring m_file;  }; 

create connections @ constructor class , initialize m_file variable:

mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent), m_file(qstring()) {     setupui(this);      connect(chosefile,  signal(clicked(bool)), this, slot(choseslot()));     connect(uploadfile, signal(clicked(bool)), this, slot(uploadslot())); } 

then time realize described slots. let's qfiledialog::getopenfilename static method result:

void mainwindow::choseslot() {     m_file = qfiledialog::getopenfilename(this, tr("open file"), qdir::currentpath(), tr("some files (*.a *.b *.c)")); } 

and if file chosen @ upload slot can tranfer them or whatever want:

void mainwindow::uploadslot() {     if (!m_file.isempty()) {         qdebug() << q_func_info << m_file;         qprocess *prc = new qprocess;         connect(prc, signal(finished(int)), prc, slot(deletelater()));         prc->setworkingdirectory("c:/avrdude");         prc->start("cmd.exe /c start avrdude.exe -c breakout -p ft0 -p m2560 -u flash:w:\"" + m_file + "\":a");     } } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -