Rice painting for Mac (how to build a Qt application for Mac OS X)

    Upd. To help in testing for different Linux distributions - join the Risovaska Friends group.

    Back in early January, I built the first working version of Risovaska for Mac and only two days ago there was a version that I’m not ashamed to show to other people. First I’ll tell you why porting to Mac took so much time, and then how to build a project on Qt for Mac OS X

    Why so long


    There was no Mac expert on the team

    It somehow happened that the entire Risovaska team was not very familiar with Mac OS X - they used Ubuntu and Windows. We bought a pair of Mac Books last year, but used them only as additional tools. And only when our long-time friend and experienced makovod Valery Hiora began to help us, the matter moved off the ground. His help in assembling the Universal version was especially invaluable - I tried to assemble it five times five without a deep understanding of the internal mechanisms, and every time I could hardly do it. But now I can read config.log :)

    There are errors in the work of Qt (4.5.0 and 4.5.1) under Mac OS X

    I suspect that few write Mac programs using C ++ and Qt. Apparently, they mainly use native tools - Objective-C, Cocoa. Here and there in Qt there are minor imperfections, different behavior of styles and layouts and other troubles.

    Xcode is very different from Visual Studio

    Completely different interface schemes, completely different (very weak) Qt support. Until you get used to it, it takes a lot of time for the simplest actions. Moreover, since it is still Unix, therefore, many things need to be put into batch files, and not done every time with your hands, which also distinguishes development in Mac OS X from development in Windows. I personally really loved the console.

    Mac OS X is a completely different world

    For the rest, there was simply not enough courage to decide for yourself that Mac OS X is really a different world that you need to study, love and be friends with.

    Quick Start Guide for Building a Qt Project on Mac OS X


    If you wrote some kind of application under Windows using Qt and want to build it under Mac OS X, here is a brief instruction for you:

    1. Install the latest version of Xcode, the gcc compiler is installed with it

    2. Download Qt - www.qtsoftware.com/downloads , we downloaded Framework Only (122 Mb)

    3. We collect Qt taking into account specifics of the project (we collected the static version):

    cd /tmp/qt-mac-opensource-desktop-4.5.1
    ./configure -prefix /Developer/Qt -qt-zlib -qt-libpng -qt-libjpeg -svg -qt-libtiff
    -qt-libmng -qt-gif -qt-sql-sqlite -openssl -universal -sdk /Developer/SDKs/MacOSX10.4u.sdk -static -release

    -prefix / Developer / Qt - where to install Qt
    -qt-zlib -qt-libpng -qt-libjpeg -svg -qt-libtiff -qt-libmng -qt-gif -qt-sql-sqlite - list of plug-in Qt plugins
    -openssl - we collect with openssl support (it needs to be installed in advance)
    -universal - to work on Intel and PowerPC processors
    -sdk /Developer/SDKs/MacOSX10.4u.sdk - path to SDK 10.4 universal
    -static - static version
    -release - release only- version, because we have already debugged the main Qt bugs -j 4 - collect in 4 threads, speeds up the assembly if there is a dual-core processor, although sub-src also loads the machine - collect only the “core” Qt, do not collect any examples and additional tilites Add to ~ / .bash_profile: That's it, Qt is installed.

    make -j 4 sub-src
    sudo make install





    PATH="/Developer/Qt/bin:$PATH"
    export PATH
    export QTDIR=/Developer/Qt
    export QMAKESPEC=macx-g++



    4. Generate an Xcode project file

    Windows project files are usually .sln and .vcproj. They indicate which files belong to the project, which additional libraries to connect, etc. We need to create the same file, but for Xcode. The good news is that you don’t have to collect it manually every time you change the project, because this process can be automated.

    Let's say that our project consists of two folders - MoodBox (UI, network and everything else) and Velasquez (drawing engine). Under Windows, we have MoodBox.vcproj, which includes all the necessary files from the Velasques folder

    4.1 Create a file with a description of the MacOS.pro project in your favorite editor

    # тут мы подключаем файлы с переводами
    TRANSLATIONS = moodbox_en.ts \
    moodbox_ru.ts

    # настройки Qt и плагинов
    QT += network xml svg
    QTPLUGIN += qjpeg qgif qmng qsvg qtiff

    # задаем иконку для проекта и имя приложения
    ICON = moodbox-dock.icns
    TARGET = MoodBox

    # добавляем пути include и библиотеки
    INCLUDEPATH += /sw/include/ImageMagick /sw/include/ImageMagick/Magick++
    LIBS += -lMagick++ -lMagickCore -lMagickWand
    LIBS += -L/sw/lib/

    # указываем DEBUG, чтобы легче отлаживаться
    DEFINES += DEBUG

    # добавляем необходимые данные в bundle
    data.path = Contents/Resources
    data.files = $$(PWD)/Avatars $$(PWD)/Clipart $$(PWD)/Sound $$(PWD)/catalogue.pal
    QMAKE_BUNDLE_DATA += data

    QMAKE_INFO_PLIST = MoodBox_Info.plist

    # убираем то ненужное, что лежит в папке MoodBox, но не нужно для сборки проекта
    HEADERS -= _PaletteConverter/stdafx.h \
    _PaletteConverter/targetver.h

    SOURCES -= _PaletteConverter/PaletteConverter.cpp \
    _PaletteConverter/stdafx.cpp \
    qtsingleapplication_win.cpp \
    qtsingleapplication_x11.cpp

    # добавляем нужные файлы из проекта Velasquez

    HEADERS += ../../Velasquez/Qt/backgroundelement.h \
    ../../Velasquez/Qt/backgroundtool.h \
    ../../Velasquez/Qt/undocommands.h \
    ../../Velasquez/Qt/varianthash.h \
    ../../Velasquez/Qt/vcommon.h

    SOURCES += ../../Velasquez/Qt/backgroundelement.cpp \
    ../../Velasquez/Qt/backgroundtool.cpp \
    ../../Velasquez/Qt/brushdrawingelement.cpp \
    ../../Velasquez/Qt/undocommands.cpp \
    ../../Velasquez/Qt/varianthash.cpp

    This file should be changed only when changing settings or when including / excluding files from other folders. New files from the MoodBox folder will connect automatically.

    4.2 Now we create a make-pro.sh script that will generate the Xcode project

    qmake -project -o MoodBox_Mac.pro
    cat MoodBox_Mac.pro MacOS.pro > tmp.pro
    mv tmp.pro MoodBox_Mac.pro
    qmake -spec macx-xcode MoodBox_Mac.pro

    4.3 Open the resulting MoodBox_Mac.xcodeproj in Xcode, agree with the choice of the project folder.

    4.4 Go to the Xcode menu: Project - Edit Active Target and set the following parameters:

    Architectures = Standard (32-bit Universal)
    Base SDK = Mac OS X 10.5
    Build active architectures only = disabled

    5. Click the big button "Build and Go"

    If the project is not very complicated, then the program will compile, link and will be launched. And if it’s complicated (there are dependencies with other libraries, there are windows-specific code, .qss styles are actively used), then you’ll have to work on it - select platform-specific code in #ifdef, split the stylesheet into general platform-specific styles, and then glue these files when downloading the application, collect third-party libraries with universal support, and much, much more.

    And here is the Mac version of Risovaska - static.risovaska.ru/Risovaska_Mac.zip
    Send feedback in the comments to this post or to the Risovaska Friends community "

    Also popular now: