简体   繁体   English

从外部Qt运行时Qt5应用程序崩溃

[英]Qt5 app crashes when run from outside Qt

I have a strange issue that appeared only recently. 我有一个奇怪的问题,直到最近才出现。

When I acces an external binary from inside my Qt app, the app crashes with the error: 当我从Qt应用程序内部访问外部二进制文件时,该应用程序崩溃并显示以下错误:

Exception Type:  EXC_CRASH (SIGABRT)

But when I run it from the "build and run" inside Qt Creator, everything runs fine when I acces the point in my application where I hit an exetrnal binary. 但是,当我从Qt Creator中的“构建并运行”运行它时,当我访问应用程序中的某个示例二进制文件时,一切运行正常。

This is the function I hit when the app crashes from outside Qt creator 这是我的应用从外部Qt创建者崩溃时遇到的功能

QString Api::getVideoFrame(QString filename, QString position)
{
    const QString ffmpeg = QDir::currentPath()+"/ffmpeg"; //mac version
    QProcess process;
    QStringList args;
    args    << "-ss" << position
            << "-i" << filename
            << "-f" << "image2"
            << "-vframes" << "1"
            //<< "-vcodec" << "bmp"
            << "pipe:1";
    process.start(ffmpeg, args);
    process.waitForFinished();

    return QString(process.readAllStandardOutput().toBase64());
}

It also crashes when accessing other external binaries, not only ffmpeg in this case. 访问其他外部二进制文件(在这种情况下不仅限于ffmpeg)时,它也会崩溃。

I have the feeling it has something to do with the QDir::currentPath() because when I mess up the path, It also crashes from inside Qt Creator. 我觉得它与QDir :: currentPath()有关,因为当我弄乱路径时,它也会从Qt Creator内部崩溃。

obviously I added the corresponding binaries next to the executable file in the Contents/MacOS/ folder 显然,我在Contents / MacOS /文件夹中的可执行文件旁边添加了相应的二进制文件

I don't really know how to debug this.. any clue how to solve this? 我真的不知道该如何调试..任何线索如何解决这个问题?

I actually found out why this happens and it is quite interresting to note that 实际上,我发现了为什么会发生这种情况,并且值得注意的是

QDir::currentPath()

has to be used with care on mac osX. 在Mac osX上必须谨慎使用。

When an app is executed from within Qt Creator it returns : 从Qt Creator中执行应用程序后,它将返回:

/Volumes/LSPRO/Build/LSPRO.app/Contents/MacOS

including the path to te binary inside the .app package 包括.app软件包中te二进制文件的路径

But when you run it as a standalone app, it returns 但是当您将其作为独立应用程序运行时,它会返回

/Volumes/LSPRO/Build

At least on my configuration... 至少在我的配置上...

I don't really know how to debug this.. any clue how to solve this?

Yes, I have some clue. 是的,我有一些线索。

You could try using QCoreApplication::applicationDirPath() for this scenario to get this working properly on MAC as also asserted by a user in the comment. 对于这种情况,您可以尝试使用QCoreApplication::applicationDirPath()来使其在MAC上正常工作,这也可以由用户在评论中断言。

Here you can find the filesystem engine source code though if you wanna further track the issue down with your suspect as a bug. 在这里,您可以找到文件系统引擎源代码,但是如果您想进一步将问题归结为可疑对象,则可以找到它。 In short, there is not much Mac specific code in there rather than Unix. 简而言之,那里没有Mac专用代码,而不是Unix。

Also, in the future you may wanna consider QtMultimedia rather than dealing with QProcess and external execution. 另外,将来您可能会考虑使用QtMultimedia,而不是处理QProcess和外部执行。

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

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