Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problems with Qt Webkit and Mac App Store

Problems with Qt Webkit and Mac App Store

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.1k Views
  • 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 Offline
    S Offline
    Sheenmue
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      gaojinhsu
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rushmore
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gaojinhsu
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rushmore
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rushmore
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gaojinhsu
                wrote on last edited by
                #7

                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
                0
                • R Offline
                  R Offline
                  rushmore
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved