Problems with Qt Webkit and Mac App Store
-
I have developed an app that uses a web view and I'm having problems to publish it in the Mac App Store as more people has reported in the past.
There's an easy solution, using an OS X native web view (I'll explain now how to do it), but that doesn't work for me because I have developed the UI with OpenGL and when I use an NS-control (not only a web view, a button, search field...) it doesn't appear. Is there a way to make it work over an OpenGL surface?
Also, I think I read in the past it's possible to compile qtwebkit without HTML5 video support (that seems to be the problem with Apple rules because it uses a private API) but now I cannot find where I read it and I'm not sure if that would work. If somebody has tried it and could explain me how to do it I would appreciate it, because I have never compiled Qt or QtWebkit.
Now, for the people that want to use a native webview in OS X this is a how to:
-
Add this line in the .pro file to use Cocoa and Webkit:
@LIBS += -framework Cocoa -framework WebKit@ -
As we are going to use Objective-C it's important that the classes that use Objective-C are in a .mm file instead of .cpp . The .pro file should look like this:
@SOURCES += main.cpp
OBJECTIVE_SOURCES += cocoaclass.mm
HEADERS += cocoaclass.h@
- Our NS view will be wrapped in a QMacCocoaViewContainer derived class. We will use that class in the rest of our Qt code like if it was a QWidget. This is a sample class with a webview that opens Google when it's created.
cocoawebview.h
@#ifndef COCOAWEBVIEW_H
#define COCOAWEBVIEW_H#include <QMacCocoaViewContainer>
class CocoaWebView : public QMacCocoaViewContainer
{
public:
CocoaWebView(QWidget *parent);
};#endif // COCOAWEBVIEW_H@
cocoawebview.mm
@#include "cocoawebview.h"
#include <WebKit/WebKit.h>
#include <Webkit/WebView.h>CocoaWebView::CocoaWebView(QWidget *parent) : QMacCocoaViewContainer(0,parent)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];NSRect rect = {{0, 0},{parent->width(), parent->height()}};
WebView *webView = [[WebView alloc] initWithFrame:rect frameName:nil groupName:nil];
setCocoaView(webView);
[[static_cast<WebView *> (this->cocoaView()) mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithString:@"http://www.google.com"]]]];
[webView release];
[pool release];
}@PS: I'm using Qt 4.8.3
-
-
You are welcome, I've rebuilt a demo and uploaded it here,I hope it could help you. https://github.com/gaojinhsu/qt-cocoa-webview