简体   繁体   English

无法从QT呼叫Matlab engOpen

[英]Fail to call Matlab engOpen from QT

I'm trying to involve matlab engine in QT creator. 我正在尝试让Matlab引擎参与QT创建者。 I am sure that I have set INCLUDEPATH and LIBS properly in the .pro file, since there is no grammar or linking problem. 我确定我已经在.pro文件中正确设置了INCLUDEPATH和LIBS,因为没有语法或链接问题。 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 我在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;
}

Every time I try to run the code in Debug or Release mode, QT says 每次我尝试以Debug或Release模式运行代码时,QT都会说

Starting D:\\qt projects\\build-VisVehicle-Qt_5_5_0-Release\\release\\VisVehicle.exe... The program has unexpectedly finished. 正在启动D:\\ qt项目\\ build-VisVehicle-Qt_5_5_0-Release \\ release \\ VisVehicle.exe ...该程序意外完成。 D:\\qt projects\\build-VisVehicle-Qt_5_5_0-Release\\release\\VisVehicle.exe crashed. D:\\ qt projects \\ build-VisVehicle-Qt_5_5_0-Release \\ release \\ VisVehicle.exe崩溃了。

By commenting out codes I found it was ep = engOpen(NULL) that caused the failure. 通过注释掉代码,我发现是导致失败的原因是ep = engOpen(NULL)。 I am using Matlab R2015a, QT 5.5.0, both 32-bit on Windows 7. I always run Matlab and QT as an administrator. 我正在Windows 7上使用32位的Matlab R2015a,QT 5.5.0。我始终以管理员身份运行Matlab和QT。 I also tried running matlab -regserver in cmd and there was a simplified Matlab command line window popped out. 我还尝试在cmd中运行matlab -regserver,弹出了一个简化的Matlab命令行窗口。 But the QT program still crashes. 但是QT程序仍然崩溃。 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. 如果有人给我一些关于此问题的想法,我将不胜感激。

Problem solved. 问题解决了。 There are two key things to do: 有两个关键的事情要做:

  1. Make sure your Qt and Matlab are both 32bit or both 64bit. 确保您的Qt和Matlab均为32位或64位。
  2. Use mingw compiler instead of msvc in Qt. 在Qt中使用mingw编译器代替msvc。

Then it will work. 然后它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM