runaway8D 2025-02-26 16:47 采纳率: 25%
浏览 23

QT调用 matlab函数库时,出现报错

请问有人遇到过这种问题吗,怎么解决呢?
在我调用matlab库的时候报的错为:

img

.pro代码为

QT       += core gui serialport printsupport opengl widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS \
            QCUSTOMPLOT_USE_OPENGL


# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    analysis.cpp \
    main.cpp \
    mainwindow.cpp \
    qcustomcalendarwidget.cpp \
    qcustomtimeedit.cpp \
    send_recive_worker.cpp \
    send_recive_worker_std.cpp

HEADERS += \
    Default_Setting.h \
    analysis.h \
    mainwindow.h \
    polyFit.h \
    qcustomcalendarwidget.h \
    qcustomtimeedit.h \
    send_recive_worker.h \
    send_recive_worker_std.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    icon.qrc

DISTFILES +=

LIBS += -lopengl32



DEFINES += __MW_STDINT_H__
# MATLAB相关库
INCLUDEPATH += D:/MATLAB/R2024b/extern/include
INCLUDEPATH += D:/MATLAB/R2024b/extern/include/win64

LIBS+=-LD:/MATLAB/R2024b/extern/lib/win64/microsoft -llibmx
LIBS+=-LD:/MATLAB/R2024b/extern/lib/win64/microsoft -llibmat
LIBS+=-LD:/MATLAB/R2024b/extern/lib/win64/microsoft  -llibeng
LIBS+=-LD:/MATLAB/R2024b/extern/lib/win64/microsoft  -lmclmcr
LIBS+=-LD:/MATLAB/R2024b/extern/lib/win64/microsoft  -lmclmcrrt



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/Ployfit/ -lpolyFit
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/Ployfit/ -lpolyFit

INCLUDEPATH += $$PWD/Polyfit
DEPENDPATH += $$PWD/Polyfit

文件位置:

img


img

  • 写回答

4条回答 默认 最新

  • 阿里嘎多学长 2025-02-26 16:47
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    QT调用matlab函数库时,出现报错

    你遇到的问题是QT调用matlab函数库时出现报错,错误信息不详细,但可以确定是matlab库相关的错误。

    解决方案:

    1. 检查matlab库的安装和配置是否正确。确保matlab库已经安装在你的系统中,并且QT可以正确地找到matlab库。
    2. 检查.pro文件中的配置是否正确。确保QT的配置文件中包含了matlab库的路径和名称。
    3. 尝试使用matlab的命令行工具来调用matlab函数库。这样可以帮助你确定问题是否是matlab库相关的。
    4. 如果问题仍然存在,可以尝试使用matlab的API来调用matlab函数库。这样可以帮助你避免一些可能的错误。

    核心代码:

    #include <QApplication>
    #include <QPluginLoader>
    #include <matlab/matlab.h>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        // 加载matlab库
        QPluginLoader loader("path/to/matlab/library.so");
        if (!loader.load()) {
            qDebug() << "Failed to load matlab library";
            return 1;
        }
    
        // 调用matlab函数
        Matlab matlab;
        matlab.eval("function_name");
    
        return app.exec();
    }
    

    注意:上面的代码只是一个示例,需要根据你的实际情况进行修改。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月26日