Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. How to find QWebFrame calling C++ API from Javascript
Forum Updated to NodeBB v4.3 + New Features

How to find QWebFrame calling C++ API from Javascript

Scheduled Pinned Locked Moved Qt WebKit
12 Posts 4 Posters 6.6k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    willc
    wrote on last edited by
    #3

    Hi Benjamin - thanks for the suggestion.

    I would need to create a new custom qobject for each new frame and use these to store the frame reference. The object would have to be deleted on a frame delete - do you know if there a signal/event for a frame delete, I can't see any in the docs?

    I seen there is an 'own' parameter for QWebFrame::addToJavaScriptWindowObject() to set the ownership - maybe if I set this to script then the delete would be handled?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      benjamin.poulain
      wrote on last edited by
      #4

      Yep, that is what I would do, set the ownership to the script engine itself.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidGOrtega
        wrote on last edited by
        #5

        Adding the QObject using ScriptOwnership is really a bad idea, the destructor is never called!! I'm figuring that this is not working at least in Qt 4.5.3

        1 Reply Last reply
        0
        • B Offline
          B Offline
          benjamin.poulain
          wrote on last edited by
          #6

          [quote author="DavidGOrtega" date="1294760299"]Adding the QObject using ScriptOwnership is really a bad idea, the destructor is never called!! I'm figuring that this is not working at least in Qt 4.5.3[/quote]

          I know about at least one big project using ScriptOwnership with 4.7 for security check on tear down. I think they would have complained if that was not working :)

          1 Reply Last reply
          0
          • W Offline
            W Offline
            willc
            wrote on last edited by
            #7

            I will test in 4.7 and let you know..

            1 Reply Last reply
            0
            • W Offline
              W Offline
              willc
              wrote on last edited by
              #8

              fyi - using ScriptOwnership worked ok for me for simple test with 4.7.

              ie. frame->addToJavaScriptWindowObject( "objectName", pObject, QScriptEngine::ScriptOwnership );

              pObject gets deleted before frame is deleted.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                willc
                wrote on last edited by
                #9

                after some further test I did find something funny using QScriptEngine::ScriptOwnership - on a page reload the object I attached to the main frame gets garbage collected!

                as an alternative I set the custom object parent to the frame and use default ownership when calling addToJavaScriptWindowObject(). This way the object gets deleted when the frame is deleted which is what I want.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dangelog
                  wrote on last edited by
                  #10

                  [quote author="willc" date="1294934025"]after some further test I did find something funny using QScriptEngine::ScriptOwnership - on a page reload the object I attached to the main frame gets garbage collected!

                  as an alternative I set the custom object parent to the frame and use default ownership when calling addToJavaScriptWindowObject(). This way the object gets deleted when the frame is deleted which is what I want.
                  [/quote]

                  Or, you can call addToJavaScriptWindowObject in a slot connected to the javaScriptWindowObjectCleared signal.

                  Software Engineer
                  KDAB (UK) Ltd., a KDAB Group company

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    benjamin.poulain
                    wrote on last edited by
                    #11

                    @willc, yep, that is intended. Custom objects are not supposed to live past the lifetime of the content. You can do as peppe says to get them from page to page.

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      willc
                      wrote on last edited by
                      #12

                      yeah - I am doing that too..

                      does anyone know the expected behaviour when an new frame (iframe) is created?

                      I have connected a function to the page "frameCreated" signal - this is called for the new frame and I call newFrame->addToJavaScriptWindowObject() to add my custom object.

                      I also connect to the javaScriptWindowObjectCleared signal for the new frame.

                      Sometimes this signal goes off immediately resulting in a second call to addToJavaScriptWindowObject() - is this expected?

                      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