Skip navigation
twright151
Currently Being Moderated

Integrating Qt into a filter plugin

Apr 19, 2011 12:59 PM

Hello,

 

I've been developing a filter plugin that requires a pretty hefty UI. I've chosen to use Qt for this because I am deploying to both mac and windows, however, it's been a little nightmarish getting all the details just right.  Things like windows staying on top etc has been problematic and very different on each platform,  I've also run into problems of being unable to use certain features of Qt like meta-types because the declaration/allocation/whatever seems to linger between runs of the filter and cause 'open twice' crashes, with all sorts of namespace smashing errors/warning sprinkled in here and there.  I've also accidently hi-jacked photoshop's menu bar (Mac OSX) causing you to be unable to quit photoshop after running my plugin.  Some 'solutions' have been put in place by myself and my co-workers but they are quite frankly a little sketchy/incomplete for my taste.

 

Does anyone know any resources (or examples) that illustrate a sane Qt/Photoshop API integration?

 
Replies
  • Currently Being Moderated
    Sep 28, 2013 2:03 PM   in reply to twright151

    Did you ever find any good documentation?  I would be very interested in the links if you did.

     

    -Tim

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 30, 2013 7:04 AM   in reply to timsvw

    Don't do it. At least on Mac there are collisions between the various Cocoa event loops and globals. We had no end of problems until we split our UI out into its own application. Makes it a lot easier to test too.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 30, 2013 9:23 AM   in reply to Shmoopie99

    Thanks for the heads up.  So when you say you split your UI to it's own application are you using QT for that and then making calls back to photoshop? 

     

    -Tim

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 30, 2013 11:14 AM   in reply to timsvw

    Yeah the external application is built entirely with Qt. Use whatever IPC you like to shlep image data around (I found simply saving the PS image to a temp file works well enough).

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 30, 2013 11:26 AM   in reply to timsvw

    Indeed there is not much documentation around about it. It's more straightforward on PC using QWinWidget; on Mac you indeed have to do some extra legwork which is pretty hacky. In the end however it works great - we've been using Qt in PS plugins for many years and while the Cocoa port was somewhat of a challenge,it did eventually work, so there is no reason to give up on it.

     

    We were considering publishing a sample stand-alone Qt plugin at some point, but with layers and layers of common libraries and platform-independed abstractions it's a lot of hassle to isolate only the code required, so we've never got around to it.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 10, 2013 8:30 AM   in reply to Shmoopie99

    I am not sure how deeply you have investigated your problems but I did port a few PS plugins from Windows to Mac using QT 4.8 and 5.1.1 on both platforms and I saw no problems that are unsolvable. I am building them with my own compiled QT (from sources) all in Xcode 4.6.2 and with OpenMP (now making that work was difficult comparing to QT) and both run absolutely fine. The amount of platform specific ifdefs is minimal (Mac requires special window setting to tell QT its a plugin) and a few others to make UI layout work a bit more predictably but that's about it.

     

    This is one of them for example (page translated to English but plugin language interface is English by default):

    http://translate.google.co.uk/translate?hl=en&sl=ru&u=http://www.uni-v ologda.ac.ru/~c3c/plug-ins/colorwizardbasic.htm&prev=/search%3Fq%3DC3C ColorWizard%26safe%3Dactive%26nfpr%3D1

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 10, 2013 8:35 AM   in reply to Alexey Danilchenko

    Things must have gotten better then! I was doing this back in the 4.2 and 4.3 time period, also during the big Carbon->Cocoa transition. Once Cocoa came about we started having problems with the Objective C bindings randomly "preferring" code from another vendor's Qt-based plugin, which of course used a different version of Qt. We never could figure out a workaround for this one.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 10, 2013 8:39 AM   in reply to Alexey Danilchenko

    Example plugin execution pattern from filter plugin entry point (for both Mac and Windows):

     

    #if defined( Q_OS_MACX )

        QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);

        QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);

     

    #endif

     

       QApplication app(argc, argv);

     

       QCoreApplication::setOrganizationName(MY_ORGANIZATION);

       QCoreApplication::setApplicationName(MY_APPLICATION);

     

    #if defined( Q_OS_MACX )

        MainWindow mainWin(0);

     

        mainWin.setWindowFlags(Qt::Window | Qt::WindowTitleHint

                                          | Qt::CustomizeWindowHint

                                          | Qt::WindowCloseButtonHint);

     

    #else

     

        PlatformData* platform = (PlatformData*)filterRecord->platformData;

     

        QWinWidget win((HWND)platform->hwnd);

     

        MainWindow mainWin(&win);

     

        mainWin.setWindowFlags(Qt::Window | Qt::WindowTitleHint

                                          | Qt::CustomizeWindowHint

                                          | Qt::WindowCloseButtonHint);

    #endif

     

        mainWin.show();

        resultCode = app.exec();

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 10, 2013 8:42 AM   in reply to fxtech

    Not really sure how that is possible - plugin using QT is bound to a specific version of the QT framework or (as in my case) compiled with QT statically (this avoids multitude of the framework packaging problems).

     

    I was only responding since the replies to the thread seem to be very recent so surely they were about recent versions of QT, PS SDK and Xcode.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 10, 2013 8:53 AM   in reply to Alexey Danilchenko

    The Mac version of the plugin I referred to above -  http://wowcamera.info/gallery/image.php?album_id=23&image_id=6388&view =no_count

    (for comparison - they are pretty similar and based on exactly teh same code and UI form and behave the same).

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 10, 2013 9:48 AM   in reply to fxtech

    fxtech: to deal with this sort of problems we compile Qt with -qtnamespace [OutPrivateNameSpace] -qtlibinfix [_OutPrivateInfix] options - this guarantees no collision with other plugins' QT distros.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points