Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:44:51+00:00 2026-06-11T03:44:51+00:00

QtWebkit segfaults whenever I return a QObject from a method of another QObject .

  • 0

QtWebkit segfaults whenever I return a QObject from a method of another QObject.

Here’s the simplest test case that I can come up with (it works for both PySide and PyQt4):

#!/usr/bin/env python2

import sys

try:
  from PyQt4.QtCore import QObject, QVariant, pyqtProperty
  from PyQt4.QtGui import QApplication
  from PyQt4.QtWebKit import QWebView

  Property = pyqtProperty
except ImportError:
  from PySide.QtCore import QObject, Property
  from PySide.QtGui import QApplication
  from PySide.QtWebKit import QWebView

class TestObject(QObject):
  @Property(str)
  def property(self):
    return 'foo'

class TestObjectContainer(QObject):
  @Property(QObject)  # Swapping QObject with TestObject doesn't fix it
  def object(self):
    return TestObject()

if __name__ == '__main__':
  application = QApplication(sys.argv)

  browser = QWebView()
  frame = browser.page().mainFrame()

  frame.addToJavaScriptWindowObject('container', TestObjectContainer())
  frame.addToJavaScriptWindowObject('test_object', TestObject())

  browser.show()

  #frame.evaluateJavaScript('test_object.property')
  frame.evaluateJavaScript('container.object.property')

  sys.exit(application.exec_())

Here is the odd part:

test_object.property;       // This doesn't segfault
container.object.property;  // This does

Is there any way to return QObjects like this? Am I doing something wrong, or is this a bug?


I ended up creating a simple wrapper class with the help of @HYRY’s answer:

class WebkitQObject(QObject):
  def __init__(self):
    super(WebkitQObject, self).__init__()
    self.__cache__ = []

  def store(self, item):
    self.__cache__.append(item)

    return self.__cache__[-1]

Now, this code works with a slight modification:

class TestObjectContainer(WebkitQObject):
  @Property(QObject)
  def object(self):
    return self.store(TestObject())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:44:53+00:00Added an answer on June 11, 2026 at 3:44 am

    You need a Python reference to the QObject to keep it alive. You can test this by changing the code as following,

    class TestObjectContainer(QObject):
      @Property(QObject)
      def object(self):
        self.tmp = TestObject()
        return self.tmp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With http://doc.qt.nokia.com/4.7-snapshot/qtwebkit-bridge.html we can expose Qt 's QObject as glabal JS objects in browser,
I want to use QtWebKit, which uses QtCore and QtGui DLLs. Can I sell
I have an application that I'm writing that uses QtWebkit and OpenSSL which deploys
I wish to use QtWebKit to load a url for display, but, that's the
I have some JavaScript from a 3rd party vendor that is initiating an image
I'm working on a finger friendly browser exercise with FlickCharm example and QtWebKit, here's
I have used the newest release of QtWebKit, that is version 2.2. But I
web_view_crash.py import sys from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.QtWebKit import
I got a QtWebKit.QWebView widget in a PyQt application window that I use to
import sys from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.QtWebKit import QWebView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.