To call a string containing file path in a command
Code:
void MainWindow::on_pushButton_clicked()
{
"S://MATLAB/",
"MATLAB Code files (*.m);;All Files (*.*)");
p->start("C:/\"Program Files\"/MATLAB/R2013a/bin/matlab.exe -nosplash -nojvm -r run('filename');");
}
Quote:
But I'm unable to use the string filename to run MATLAB script file. Instead of sending the file path like "S:/MATLAB/test.m" , the variable name "filename" is being executed in the run command. I have to manually enter the file path. Is there any other way to redirect the file path to run it directly on a mouse-click.?
Re: To call a string containing file path in a command
You need to use the value of variable 'filename' and not the string constant "filename".
Code:
p
->start
( QString("C:/\"Program Files\"/MATLAB/R2013a/bin/matlab.exe -nosplash -nojvm -r run('%1');").
arg(filename
) );
Code:
void function(const QString& s);
...
...
function(string);
...
function("string");
Do you understand the difference between the two above function calls ?
Re: To call a string containing file path in a command
Re: To call a string containing file path in a command
But what if my filename was S:/MATLAB files/test.m
In console window of MATLAB only the first part of the command i.e., run('S:/MATLAB is being executed giving an error :A MATLAB string constant is not terminated properly.
Re: To call a string containing file path in a command
Use another variant of start method :
Code:
QString app
( "C:/Program Files/MATLAB/R2013a/bin/matlab.exe" );
arguments <<
"-nosplash" <<
"-nojvm" <<
"-r" <<
QString("run('%1')").
arg(filename
);
p->start(app,arguments);
Re: To call a string containing file path in a command
You need to use proper shell escaping or use a variant of QProcess::start() which accepts arguments in separate strings.