Interact with a QQmlApplicationEngine html page.



  • I just set up a QtWebEngine which opens an HTML file. I have not written the HTML myself. I need to interact with it.

    I have been told that it's name gets changef when a user gives certain inputs. What the user has done is than stored in the name. This was principle is being used succesfully with visual basic 6. Anyways the precise details are also a bit of a mistery to me. Long story short, all I need is to get data out of the webview browser's html

    alt text
    I hope the screenshot works for once -_-"

    I am trying to get the data out of it with:

    connect(engine, &QQmlApplicationEngine::objectNameChanged, this, &MainWindow::browserInteraction);
    

    But as you can guess, it's giving me an error message

    /home/user/Dropbox/GUI/GUI_Qt/mainwindow.cpp:63: error: no matching function for call to ‘MainWindow::connect(QQmlApplicationEngine&, void (QObject::*)(const QString&, QObject::QPrivateSignal), MainWindow*, void (MainWindow::*)())’
        connect(engine, &QQmlApplicationEngine::objectNameChanged, this, &MainWindow::browserInteraction);
                                                                                                        ^
    

    I have a function 'browserInteraction' in which I want to retrieve the objectname and process it to see if I can use this method.


  • Moderators

    @bask185 Is engine a pointer?



  • Facepalm -_-" .....it is now, but now my application crashes before it starts.

    The connect line crashes the program, outcommenting it, removes the crash.

    Also I changed this: engine.load(QUrl(QStringLiteral("qrc:/resources/img/webview.qml")));
    in this: engine->load(QUrl(QStringLiteral("qrc:/resources/img/webview.qml")));
    to keep the compiler happy. When I execute this line of code the program also crashes.

    In MaindWindow.h: QQmlApplicationEngine *engine;



  • @jsulm Do you know if/how I can find the cause to why it crashes. I mean does Qt creator has some kind of crash log or something?


  • Lifetime Qt Champion

    Hi,

    You seem to be using a MinGW build of Qt, then you should already have a debugger. Just start your application in debug mode and you should get some interesting stuff.

    Hope it helps.


  • Moderators

    @bask185 Did you create an instance of QQmlApplicationEngine and assign the pointer to engine?

    engine = new QQmlApplicationEngine();
    


  • No I forgot this. I will learn it someday, I hope ;)

    This webview is becomming a payne, I'm running in one issue after the other.

    I just solved the obstacle of closing the webview. I could not use -> exit() or-> close() because those are signals which kill the entire program.

    Eventually I learned that I can close the webbrowser with the function ''->deleteLater();" but this works one whole time. The 2nd time I try to open the webbrowser...

    The inferior stopped because it received a signal from the operating system.
    
    Signal name : 
    SIGSEGV
    Signal meaning : 
    Segmentation fault
    
    

    aka crash.

    I just want to be able to close the webview just like you do when you press the x. The x is not present on my target device so I need to close the webview in code, I suppose that hiding it underneath my GUI is also an acceptable option. If it is possible that is.

    And I still cannot retrieve information out of the html. In the html there is this line

    document.title=txtString
    

    The idea is.... was that when this this rule gets executed, the object name changes and I could get information out of it using the 'objectNameChanged' signal. But it does not seem to work. The html also has it's own exit option but it does not.... exits anything. I added document.close(); to the function in question, but nothing -_-"*

    Anyways I am open to suggestions.... on Qt's end ofcourse. I have 0,0 experience and knowledge of QML and HTML. And if it would be up to me, I'd be recreating the html in a new Qt window.


  • Moderators

    @bask185 Why not just call hide()?
    If you delete it and try to access it later then yes your app will crash as you're trying to access memory you freed before...



  • @jsulm said in Interact with a QQmlApplicationEngine html page.:

    @bask185 Why not just call hide()?

    For once I am on step ahead of you, I think ;) The answer to this question:

    /home/user/Dropbox/GUI/GUI_Qt/mainwindow.cpp:151: error: ‘class QQmlApplicationEngine’ has no member named ‘hide’
       engine->hide();
               ^
    

    The code in the setup is now:

    QtWebEngine::initialize();
    engine->load(QUrl(QStringLiteral("qrc:/resources/img/webview.qml")));
    engine->hide();
    

    @jsulm said in Interact with a QQmlApplicationEngine html page.:

    If you delete it and try to access it later then yes your app will crash as you're trying to access memory you freed before...

    I figured something like that is why I tried to call ::initialize() again before opening. But I believe 'deleteLater()' deletes the object/member I declared in the header file -->> crash ???


  • Moderators

    @bask185 You cannot call anything on something what was already deleted (deleteLater() deletes the object).



  • @jsulm said in Interact with a QQmlApplicationEngine html page.:

    @bask185 You cannot call anything on something what was already deleted (deleteLater() deletes the object).

    Yes and I scrolled through the list of functions but I cannot find anything which simply closes the webview window


  • Moderators

    @bask185 QWebView is derived from QWidget and QWidget has hide() method



  • @jsulm said in Interact with a QQmlApplicationEngine html page.:

    @bask185 QWebView is derived from QWidget and QWidget has hide() method

    But 'member that the thing I am using:

    engine = new QQmlApplicationEngine();
    

    is not derived from a QWidget IIRC.

    I am using this QML file:

    import QtQuick 2.0
    import QtQuick.Window 2.0
    import QtWebEngine 1.0
    
    Window {
        width: 1024
        height: 750
        visible: true
        WebEngineView {
            anchors.fill: parent
            url: "qrc:/resources/img/frmSSPeditor.html"
        }
    }
    

    to open the .html

    And I did this because this was recommended to me on this here forum.
    @raven-worx said in Browsers and Java Script.:

    @bask185
    QtWebkit is deprecated in the meantime and has been replaced by QtWebEngine (based on Chromium).
    Try using WebEngineView instead.

    This + I am not seeing the QWebview widget in Qt creator.

    alt text
    No suggestions for hide, can only find 'handle'. I am telling you hide() isn't there


  • Moderators

    @bask185 How did you add that engine to your GUI? Does it have a parent widget? Is it in a layout?



  • @jsulm said in Interact with a QQmlApplicationEngine html page.:

    @bask185 How did you add that engine to your GUI? Does it have a parent widget? Is it in a layout?

    It has no parent Widgets. In the header file I declare: QQmlApplicationEngine *engine;
    In the setup I initialize it:
    engine = new QQmlApplicationEngine(); //(this action is called initializing right??)
    and I also perform QtWebEngine::initialize();

    In a function I call: engine->load(QUrl(QStringLiteral("qrc:/resources/img/webview.qml")));
    And this line opens a new window with the .qml which opens the .html

    It is not related to any .ui I also have no controll where the window appears. The reso of the target device is that small that it is just right.

    But if you can tell me how to install the QWebview widget in Qt creator, that also works for me.


  • Moderators

    @bask185 said in Interact with a QQmlApplicationEngine html page.:

    QWebview

    Why don't you use http://doc.qt.io/qt-5/qwebengineview.html? QtWebKit is discontinued QWebEngine should be used instead.



  • @jsulm Becuz I sometimes have no idea of how to get my stuff to work, hence my presence on this here forum ;)

    Anways my entire app works like a charm, mostly thanks to your efforts, So thank you!

    Even the titleChanged() signal works out of the box, I only have to retrieve some information out of a column somewhere


  • Moderators

    @bask185 Glad to hear it works now :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.