×

Discussion Board

Results 1 to 3 of 3

Thread: QML webview

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    QML webview

    Hi.

    I have built an app that consists of a QML WebView and now I'd like to catch all the on-link-clicks and handle them with C++.

    Is it possible to cast a QML WebView element to a QWebView object or expose C++ methods to QML?
    Or is there any other way to achieve what i'm looking for?

    Thanks.
    Last edited by ENEX; 2011-04-21 at 14:53.

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Re: QML webview

    So, I guess I figured out how to expose some C++ methods to QML.
    The problem is that everytime I try to run my code I got the following error message: "undefined reference to `vtable for MyClass".

    Any help on this?

    The code:

    Code:
    class MyClass : public QObject
    {
        Q_OBJECT
    public:
        Q_INVOKABLE void cppMethod(const QString &msg) {
            qDebug() << "Called the C++ method with" << msg;
        }
    
    public slots:
        void cppSlot(int number) {
            qDebug() << "Called the C++ slot with" << number;
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QDeclarativeView view;
        MyClass myClass;
        view.rootContext()->setContextProperty("myObject", &myClass);
        view.setSource(QUrl::fromLocalFile("qml/expose/main.qml"));
        view.show();
    
        return app.exec();
    
    }

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    166

    Re: QML webview

    I will suggest to move your QObject based class to seperate file and the try to use it. Please visit following link for more info.
    http://kunalmaemo.blogspot.com/2011/...ml-and-qt.html

    BTW were you able to "catch all the on-link-clicks" event from QML web view ?
    http://kunalmaemo.blogspot.com/

Similar Threads

  1. How to call/load another QML file from QML ?
    By cadlg in forum [Archived] Qt Quick
    Replies: 5
    Last Post: 2011-07-28, 09:15
  2. [Qt QML] Questions regarding QML Performance
    By SeanZhang in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-05-05, 13:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •