Nicholas Corin
Nicholas Corin

Reputation: 2404

Qt Libraries cannot be found on Mac

I'm having issues setting up the Qt environment on Mac 10.9.1. If I just try to compile a C++ file with the standard

 g++ source.cpp -o output 
Then none of the Qt Libraries are found. For instance if I have

#include <QString>

Then I will get the error

fatal error: 'QString' file not found

I have installed Qt 5.2.1 and added it to my PATH variable, so now when i make the project using

qmake -project, qmake -spec macx-g++ and then make

I get the error saying that my version of Mac OSX is not supported. I have to use Qt for my college assignment, please can someone help me set this up.

Any help would be appreciated.

Upvotes: 1

Views: 2948

Answers (1)

Mavericks is definitely supported by Qt 5. It is not supported by Qt 4 so far; trojanfoe made a typo in his comment (nomen est omen?).

Your mistake is using the wrong make spec. Qt 5 uses clang, not gcc. Thus the following works for me (without setting any paths):

~/Qt5.2.1/5.2.1/clang_64/bin/qmake -project
~/Qt5.2.1/5.2.1/clang_64/bin/qmake -spec macx-clang
make

You can have multiple Qt versions existing side by side, there's no reason to uninstall anything when you get a new Qt version installed.

A small self-contained example would be below. Put it in a simple folder. To build, do:

~/Qt5.2.1/5.2.1/clang_64/bin/qmake -spec macx-clang
make

You do not want to regenerate the .pro file by invoking qmake with -project argument. The project generation is just to give you a simple skeleton, you're only supposed to do it as a convenience when importing third-party code.

Note that by definition if you use any visible GUI elements (windows, message boxes, etc), it's not a console application anymore as far as Qt is concerned.

# simple.pro
TEMPLATE = app
QT += widgets
# Creates a simple executable instead of an app bundle
CONFIG -= app_bundle
SOURCES += main.cpp
// main.cpp
#include <QApplication>
#include <QMessageBox>

int main(int argc, char ** argv)
{
  // It is an error not to have an instance of QApplication.
  // This implies that having an instance of QCoreApplication and QGuiApplication
  // is also an error.
  QApplication app(argc, argv);
  QMessageBox::information(NULL, "Get This!", "Something's going on");
}

Upvotes: 2

Related Questions