0

I faced the strange situation on MacOS 10.13 and can't find what is the root of it.

I have 32-bit Qt application packed in a bundle. Because of MacOS limitation for one of the operations I need to start small 64-bit console binary that does a trick. This console binary placed in Contents/MacOS and I start it using QProcess.

Everything works fine if I run the main application from IDE. Also, everything fine if I open a terminal, cd to Contents/MacOS and run the main application directly.

But once I use "open myApp.app" or start it via UI, then QProcess exitCode() returns 255, which seems to mean crash.

Code for starting subprocess:

QProcess p;
p.start("./papply", QStringList() << osid << filepath);
p.waitForFinished(5000);
qDebug() << p.readAllStandardOutput();
qDebug() << p.readAllStandardError();
qDebug() << p.state();
if(p.state()==QProcess::Running)
{
  qDebug() << "peapply freezed - kill";
  p.kill();
  return false;
}

qDebug() << "Apply" << osid << filepath << "=" << p.exitCode();
return p.exitCode()==0;

Any help will be very appreciated.

johngull
  • 819
  • 6
  • 22

2 Answers2

1

I have 32-bit Qt application packed in a bundle.

Firstly, just in-case you missed this, Apple have stated that the next version of the OS (10.14) will not support 32-bit applications, so you'll need to change this if you want to run this application on future versions of macOS.

If you use the debugger, or run a binary from a bundle's Contents/MacOS folder, it executes directly. In contrast, if you double-click on a binary, or use the open keyword from the terminal, a request is sent to Launch Services, to open the application on your behalf.

Launch Services (LS) maintains an association to an application's Bundle Identifier, which is located in the application bundle's Info.plist file.

When a request to open an application with LS occurs, LS is presented with the Bundle Identifier, from the application's plist and LS will execute the application that has been registered, with that identifier.

In the plist, we also have the key CFBundleExecutable, which is defined as the "(Recommended) Name of the bundle's executable file". This is the name of the binary that will likely be executed, residing in the Contents/MacOS folder.

Note, since LS launches the application associated with the given identifier, if there is a copy of the same application on your machine, with the same version number and identifier, it may not be necessarily executing the application you double-clicked, to run.

Therefore, the reason for the crash is most likely due to a different application being launched by LS and not the one you think is being executed. Ensure you have no other copies of the application residing on the machine.

If a crash report is generated, you should be able to see the path to the application, at the start of the images section, where it includes paths to dynamic libraries and frameworks.

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • Thank you. That was not my case as I had only one instance of the application which was properly installed. But anyway your information is very interesting and helpful. – johngull Oct 11 '17 at 08:34
0

While @TheDarkKnight provided great information that is not exactly an answer.

For people who will face the same situation: In macOS bundle application has working directory related to bundle, but not to the execution file itself as it happens in Windows.

So in my case next code works:

QString path = qApp->applicationDirPath();
if(!path.endsWith("/"))
    path += "/";
QProcess p;
p.start(path + "papply", QStringList() << osid << filepath);
johngull
  • 819
  • 6
  • 22