我正在尝试将 matlab 引擎包含在 QT 创建器中。我确信我已经在 .pro 文件中正确设置了 INCLUDEPATH 和 LIBS,因为没有语法或链接问题。我添加了
D:\Program Files\Matlab32\bin;
D:\Program Files\Matlab32\runtime\win32;
D:\Program Files\Matlab32\bin\win32
到我的路径。在我写的 mainwindow.cpp
#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;
}
每次我尝试在调试或发布模式下运行代码时,QT 都会说
正在启动 D:\qt projects\build-VisVehicle-Qt_5_5_0-Release\release\VisVehicle.exe... 程序意外完成。D:\qt projects\build-VisVehicle-Qt_5_5_0-Release\release\VisVehicle.exe 崩溃。
通过注释掉代码,我发现是 ep = engOpen(NULL) 导致了失败。我在 Windows 7 上使用 Matlab R2015a、QT 5.5.0,都是 32 位的。我总是以管理员身份运行 Matlab 和 QT。我还尝试在 cmd 中运行 matlab -regserver 并弹出一个简化的 Matlab 命令行窗口。但是 QT 程序仍然崩溃。每当我对代码或环境进行更改时,我都会仔细清理并重新构建程序,以避免潜在的构建问题。
如果有人给我一些关于这个问题的想法,我将不胜感激。