I'm making an application which will be able to program my board. I would like to select file via file dialog and upload board with selected file by upload button. I have two class to it: MyFileDialog and CommandProcess. I connected upload button clicked signal to signal mapper and i mapped it to CommandProcess::startProcess slot, which executes process with path of selected file but the path is incorrect if I don't indicate it on start of program. How can I update mapping parameter after i 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 at your
MainWindow
class andQString
member for storing path to file like this:Create connections at your constructor class and initialize
m_file
variable:Then time to realize described slots. Let's get
QFileDialog::getOpenFileName
static method result:And if file already chosen at upload slot we can tranfer them or do whatever you want: