0

I'm trying to involve matlab engine in QT creator. I am sure that I have set INCLUDEPATH and LIBS properly in the .pro file, since there is no grammar or linking problem. I added

D:\Program Files\Matlab32\bin;
D:\Program Files\Matlab32\runtime\win32;
D:\Program Files\Matlab32\bin\win32

to my Path. In the mainwindow.cpp I wrote

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "engine.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

qDebug() << "Trying to open the engine";
Engine *ep;
ep = engOpen(NULL);
engClose(ep);

}

MainWindow::~MainWindow()
{
    delete ui;
}

Every time I try to run the code in Debug or Release mode, QT says

Starting D:\qt projects\build-VisVehicle-Qt_5_5_0-Release\release\VisVehicle.exe... The program has unexpectedly finished. D:\qt projects\build-VisVehicle-Qt_5_5_0-Release\release\VisVehicle.exe crashed.

By commenting out codes I found it was ep = engOpen(NULL) that caused the failure. I am using Matlab R2015a, QT 5.5.0, both 32-bit on Windows 7. I always run Matlab and QT as an administrator. I also tried running matlab -regserver in cmd and there was a simplified Matlab command line window popped out. But the QT program still crashes. And whenever I made changes to the code or environment, I carefully clean and rebuild the program to avoid potential build issues.

I'd be very grateful if anyone gives me some idea about this issue.

1 Answers1

0

Problem solved. There are two key things to do:

  1. Make sure your Qt and Matlab are both 32bit or both 64bit.
  2. Use mingw compiler instead of msvc in Qt.

Then it will work.