I have been working with James George on a way to integrate OF with Qt, i.e. compile OF apps that spawn and utilize Qt UI windows. While there has been discussion about using Qt Creator as an IDE for OF on Linux, this is instead an attempt at integrating Qt and OF. Our motivation for doing this is to develop a cross-platform workflow for OF apps that require robust, native UI’s.
Here’s what we could use help with:
- This only compiles with the 64-bit OF 0.9.0, which I had to modify slightly for qmake to compile it. Specifically, I changed some file extensions from .cpp to .mm. I couldn’t figure out how to compile OF + Qt with the 32-bit version of OF or unmodified 64-bit version, but would appreciate any suggestions as the current setup is a bit of a hack.
- Currently, you have to manually add libfmodex.dylib to ofTestApp > Contents > MacOS for the example app to link properly. Is there a way to avoid doing this with a copy script, maybe something in the ofTestApp .pro file?
- ofQt has only been tested on OSX 10.10. Does this approach work on Windows?
- OF + Qt has only been tested with Qt Creator
- Executing the QApplication in main.cpp prevents OF from starting, although the QApplication must be initialized for the Qt window to open in the first place. This shouldn’t be a problem if you’re only using Qt for a UI.
Steps to get ofQt running:
Clone ofQt from our repo
In Qt Creator: File > Open File or Project > [/path/to/ofQt.pro] > Configure Project
Expand the project tree on the left panel and select “openFrameworksLib”
Build > Build Subproject “openFrameworksLib” (this will take a few minutes)
Build > Build Project “ofQt” (Note: you may get an error “Library not loaded: ./libfmodex.dylib”; to fix this, manually copy from libfmodex.dylib from of_v0.9.0/libs/fmodex/lib/osx to build-ofQt-Desktop_Qt_5_4_2_clang_64bit-Debug/ofTestApp/ofTestApp/Contents/MacOS/, thenbuild again)
Build > Run
ofQt contains a simple example that lets you control the size of an ellipse with a Qt slider, and manipulate values in a Qt table. You should be able to compile the project in Qt Creator without any special setup, so long as you use the custom copy of OF included in the repo.
ofQt uses the layout described in this StackOverflow post. This is what Qt Creator calls a “subdirs project”, in which OF is a static library and ofTestApp is a subproject. The tree structure looks like this:
The main .pro file ofQt.pro shows the relationships between the container project, the subproject and static lib:
TEMPLATE = subdirs CONFIG += ordered SUBDIRS += \ ofTestApp \ openFrameworksLib ofTestApp.depends = openFrameworksLib
There are three .pro files in total: 1) the container project ofQt, 2) the app subproject ofTestApp which contains the OF app and the Qt UI file, 3) openFrameworksLib, or the OF static library. The Qt UI is defined in mainwindow.ui, which you can edit visually in Qt Creator.