3

How would you convert the following simple QT example in C using the QWebView widget to Java (QtJambi):

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWebView view;
    view.load(QUrl("http://www.trolltech.com/"));
    view.show();
    return app.exec();
}

(Located at: http://doc.qt.nokia.com/qq/qq26-webplugin.html#qtwebkitbasics)

I could be mistaken but I think I recall such an example being present in the Qt-Jambi javadoc last year, but I can't find it any more, when I go to http://qt-jambi.org/documentation it says "Apidoc of newest built (sic) is not still working"

Dexygen
  • 12,287
  • 13
  • 80
  • 147
  • The Java API docs do not build anymore since Qt and the 'qdoc3' tool used produce them had its Java/javadoc support removed. I think this was because the stewards (at the time) Nokia no longer supported Java and did not have the time or interest to maintain it along with the C++ business requirements. But there is a strategy to create an alternative mechansim to produce them once the task priority makes the top of the backlog list. – Darryl Miles Oct 18 '12 at 22:42

1 Answers1

2

The API in Qt Jambi is very similar to the original Qt API so the samples can be translated almost directly.

So the C++ version

QWebView view;
view.load(QUrl("http://www.trolltech.com/"));

Is translated to the following in Java

QWebView view = new QWebView();
view.load(new QUrl("http://www.trolltech.com/"));

The rest of the application (creating the main window, running the app) can be found in the hello world tutorial.

I don't have a working environment on my home mac, but this sample should work:

import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;
import com.trolltech.qt.webkit.*;

public class SO12093494 extends QMainWindow {

   private QWebView webView;

   public SO12093494() { this(null); }
   public SO12093494(QWidget parent) {
      super(parent);

      webView = new QWebView();
      setCentralWidget(webView);
   }

   public void loadUrl(String url) {
      webView.load(new QUrl(url));
   }

   public static void main(String[] args) {
      QApplication.initialize(args);

      SO12093494 app = new SO12093494();
      app.loadUrl("http://www.trolltech.com");
      app.show();

      QApplication.exec();
   }
}
Alex
  • 25,147
  • 6
  • 59
  • 55