1

我希望为 Qt 应用程序(可以使用任何 c++ 方法或库)实现一种方法来访问/查找由 Matlab 进程创建的映射内存文件。我已经阅读了几个关于如何在特定环境中执行共享内存的示例(即在 Matlab 或 Qt 或 VS 中创建的 2 个进程),但没有人谈论如何从另一个程序中查找映射文件。有没有办法做到这一点?

这是我映射文件的 Matlab 脚本:

filename = fullfile(tempdir, 'test.dat');
[f,~]=fopen(filename,'wb');
fwrite(f,67,'uint8');
fclose(f);

m = memmapfile(filename,'Writable',true,'Format','uint8');
keyboard

我对从 Qt 写入映射文件并不感兴趣,现在我只是想知道它是否存在,然后可能在将来写入它。我想在 Qt 中尝试的唯一一件事就是查看文件是否存在,但我的尝试从根本上是有缺陷的,因为据我所知,我想知道文件是否被映射(寻找内存地址?)而不是它是否存在在硬盘上。

#include <QCoreApplication>
#include <QSharedMemory>
#include <QFile>
#include <QTextStream>
#include <QString>

void read(QString filename)
{
    QFile file(filename);
    if (!file.exists()) {
        QTextStream(stdout) << "File does not exist!" << endl;
    }
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString filename = "C:/Users/Engineer/AppData/Local/Temp/test.dat";
    read(filename);

    return a.exec();
}

有没有人尝试过这样做?谁能指出我正确的方向?

4

0 回答 0