I need to call Matlab
function from Qt
. I know that there are standard way to do it via Engine
, but I was not able to connect .lib
libraries (I think because I use Mingw compiler). So, as I understand QProcess
is the only way to do it. I have studied examples and wrote simple program, which has one QLineEdit
(for Matlab script) and two QPushButton
(for send script to Matlab and read response). Here is code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
proc = new QProcess(this);
proc->start("\"C:\\Program Files\\MATLAB\\R2013b\\bin\\matlab.exe\"");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_readButton_clicked()
{
QByteArray dataError = proc->readAllStandardError();
qDebug()<<dataError;
QByteArray dataOutput = proc->readAllStandardOutput();
qDebug()<<dataOutput;
}
void MainWindow::on_writeButton_clicked()
{
QString text = ui->textForMatlab->text();
QByteArray script;
script.append(text);
qDebug()<<script;
proc->write(script);
}
When I start that program matlab.exe is launching. But when I type something in QLineEdit
and click write button there is no response from matlab. Could you tell me what I am doing wrong?