Make a native Mac App Bundle of Qt Designer with Qt Jambi

01Nov09

Qt Designer is an important tool for designing and building graphical user interface from Qt components. However, if you are a Java programmer and want to use Qt Designer with Qt Jambi in Mac, you can’t simply double-click the Designer app bundle shipped with Qt Jambi SDK. If you do so, you can still invoke the Designer, but… with the C++ environments, it’s useless for Java programmers. Instead, if you want to use Qt Designer with Qt Jambi. You have to start the program from a `designer.sh` script placed in your Qt directory. It’s pretty annoying because you’ll need a Terminal to run this script until you turn it off. Also, it’s not intuitive.

So, I checked the script code and found what it does is simply to set some environment variables and then execute the Designer binary within the Designer app bundle. Therefore, I decided to make a “real” app bundle for the Qt Designer with Qt Jambi. It’s pretty easy to do this job by using Jump, one of my open source projects. Here’s the instructions.

  1. Go to the `QTDIR/bin` directory in Finder.
  2. Right-click the `Designer` app bundle, select `Show Package Contents`, and it will open a new Finder window.
  3. In the new opened Finder window, go to the `Contents/MacOS` directory, then copy the `Designer` binary back to `QTDIR/bin`.
  4. Now pick a location to start writing our wrapper. I simply make a directory called `designer` in my home directory, then open a Terminal and switch to it.
  5. Back to the new opened Finder window, copy the `Contents/Resources/designer.icns` file to our new created `designer` directory.
  6. Create a Python module named `designer.py` in `designer` directory, and its content looks like this:
    import os
    # Replace this path to your QTDIR
    qt_home = '/Users/olliwang/workspace/qtjambi-mac-lgpl-4.5.2_01'
    
    def main():
        os.environ['QTDIR'] = qt_home
        os.environ['DYLD_LIBRARY_PATH'] = os.path.join(qt_home, 'lib')
        os.environ['QT_PLUGIN_PATH'] = os.path.join(qt_home, 'plugins')
        os.environ['PATH'] = os.path.join(qt_home, 'bin')
    
        classpaths = []
        for filename in os.listdir(qt_home):
            if filename.endswith('.jar'):
                classpath = os.path.join(qt_home, filename)
                classpaths.append(classpath)
        os.environ['CLASSPATH'] = ':'.join(classpaths)
        os.system(os.path.join(qt_home, 'bin/Designer'))
  7. Create a `config.jp` file with following content:
    dist_name = Designer
    main_entry_point = designer:main
    icns = designer.icns
  8. Run `jump app` in your Terminal, and you’ll see a new created directory called `dist`, our new app bundle is in there.
  9. Copy the created app bundle back to the `QTDIR/bin` directory, now double-click the `Designer` app bundle and everything should work fine. Cheers!

I use Python to write this wrapper for easy, you can of course do the same thing in Java. Just remember to modify the `main_entry_point` to the `Main Class` in config file.

Advertisement


No Responses Yet to “Make a native Mac App Bundle of Qt Designer with Qt Jambi”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.