Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can I get QImage of a QWebView from another thread?



  • I am trying to get pixels from QWebView in my application regularly, like every 30 f/s, and I dont want to block the mainthread, so QWebView can run normallly. But I got following message, which seems that it has to be in mainthread.

    Is it possible that I create another process and use it only for getting pixels from QWebView, so that QWebView will be in Mainthread and wont affect the application's main thread, could it be a solution? (I have not done anything like it before, the concept may not right.)

    Is there any other solution? Thank you.

    ASSERTION FAILED: isMainThread()
    c:\work\build\qt5_workdir\w\s\qtwebkit\source\webcore\dom\Document.cpp(1851) : WebCore::Document::updateStyleIfNeeded
    ...



  • Hi,
    All GUI elements need to be in the MainThread, that is why you get the assertion. GUI (widgets) are not thread safe!

    Working with different threads is possible, but have a signal be emitted by the QWebView (Mainthread) when new data is available and catch that in a slot in your handling thread.
    If both application main thread and QWebView are using GUI elements it not valid to do it multithreading!



  • Thank you for your quick reply.

    Would you please tell me which signal I should use? There is no event that can tell me that pixels has been changed in QWebView.

    Or Is there any class from qwebkit that is not GUI element and I can use it to get bitmap basicly.

    [quote author="Jeroentje@home" date="1398679981"]Hi,
    All GUI elements need to be in the MainThread, that is why you get the assertion. GUI (widgets) are not thread safe!

    Working with different threads is possible, but have a signal be emitted by the QWebView (Mainthread) when new data is available and catch that in a slot in your handling thread.
    If both application main thread and QWebView are using GUI elements it not valid to do it multithreading![/quote]



  • QWebView is a Widget, so no, you can't use multitheading or place it outside your mainthread.
    The biggest question now is, what do you need, what do you want? Only to give the best answer to your problem, not just a solution for this particular question.



  • What I mainly need is to get pixel values from QWebView and I will send them over the network to other computers with good framerate.

    Since getting pixels block the main thread, it will interfere UI usage, for exmaple, if I open youtube page, it playback will be very stuttering, because of the code which tries to get pixels blocks it.

    [quote author="Jeroentje@home" date="1398681097"]QWebView is a Widget, so no, you can't use multitheading or place it outside your mainthread.
    The biggest question now is, what do you need, what do you want? Only to give the best answer to your problem, not just a solution for this particular question. [/quote]


Log in to reply