Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Problems with Qt Webkit and Mac App Store

    General and Desktop
    3
    8
    3728
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Sheenmue last edited by

      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:

      1. Add this line in the .pro file to use Cocoa and Webkit:
        @LIBS += -framework Cocoa -framework WebKit@

      2. 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@

      1. 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

      1 Reply Last reply Reply Quote 0
      • G
        gaojinhsu last edited by

        Good enough to solve it temporarily. I have succeed to pass the review of the MAS.

        1 Reply Last reply Reply Quote 0
        • R
          rushmore last edited by

          How do you detect url redirecting with this method? Thanks.

          1 Reply Last reply Reply Quote 0
          • G
            gaojinhsu last edited by

            What's your email? I could give you my sample code.

            1 Reply Last reply Reply Quote 0
            • R
              rushmore last edited by

              Can you click on my profile and send email from there? Thank you so much! I really appreciate it!

              1 Reply Last reply Reply Quote 0
              • R
                rushmore last edited by

                I just sent you my email address via forum message. Thank you!

                1 Reply Last reply Reply Quote 0
                • G
                  gaojinhsu last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • R
                    rushmore last edited by

                    This is a life saver... Thank you so much!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post