Search code examples
c++objective-cmacosqtwebkit

How does one build a custom native OSX webkit widget in Qt/C++?


How does one build a custom widget in Qt/C++ (version 5.5) that loads the native OSX webkit? I read this tutorial but need to do something more powerful because Qt doesn't already contain the native webkit.

Qt 5.5 has a "tech preview" for the native webkit, but it's buggy -- when you load form controls, they appear all wonky.

I've taught myself some Objective C. So, I was wondering if I had to build something in Objective C and then somehow load it inside Qt/C++?

Or, perhaps I can build the interface in Objective C and then have it call Qt/C++?

Ultimately, here's what I want:

  • Uses native OSX webkit, not the one bundled with Qt, not the tech preview.

  • Embeds a link to my Qt/C++ class in Javascript. So, I can do something like: var sFileSelection = cpp.selectFile('*.txt'); and it calls a Qt class method selectFile(QString sFile) to do work such as show a popup select file window, and then Javascript receives this back in sFileSelection.


Solution

  • The better solution that has been proposed is to develop the app's GUI in Objective C, and then call a Qt/C++ Dylib (the equivalent of a DLL on Windows) from the Objective C to do the heavy-lifting. (Assuming you prefer to do most of the coding in Qt.) The drawback of the Qt Dylib is that it cannot draw GUI components or show things like a file dialog because it has no application context handle to use for such things. Therefore, those GUI things must be called from ObjectiveC. However, one can have the class method in Qt and then it can send a message back to ObjectiveC to call one of its own class methods.

    As for how to load a Dylib created with Qt inside an Objective C application, that's another question entirely.