KcFnMi
KcFnMi

Reputation: 6171

How to execute a Qt app on macOS Terminal?

When I execute the following on QtCreator I do see the hello world printed on the screen. However if I exectue it from Terminal by doing open project.app, then there is no output. Why? Perhaps I'm not executing it the right way, so how to execute a Qt app on macOS Terminal?

main.cpp

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qDebug() << "hello world";
    return a.exec();
}

project.pro

QT += core 
CONFIG += c++11 console app_bundle
SOURCES += main.cpp 

I tried the following but looks like there might be other problems going on:

$ ./project.app/Contents/MacOS/project 
dyld: Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets
  Referenced from: /Users/user/QtProjecs/project/./project.app/Contents/MacOS/project
  Reason: Incompatible library version: project requires version 5.13.0 or later, but QtWidgets provides version 5.7.0
Abort trap: 6

Upvotes: 1

Views: 1336

Answers (1)

Jeremy Friesner
Jeremy Friesner

Reputation: 73091

MacOS/X .app folders hide their executable in the Contents/MacOS subdirectory, so if you want to execute the executable directly and see its output in Terminal, you'd run it like this:

 ./project.app/Contents/MacOS/project

Upvotes: 2

Related Questions