I am using a QWebFrame to visualize some data and I use evalueateJavascript method to update data on Javascript. Here is my function to do this.
QWebFrame * webFrame;
void setValue(int idx, double value){
webPage->page()->mainFrame()->evaluateJavaScript(QString("setDataValue(%1,%2)").arg(QString::number(idx)).arg(QString::number(value)));
}
In QT application I can call this function via a button call back as many time without causing an error.
I want to call this setValue function from a separate thread to visualize incoming data. When I call setValue function from a separate thread, after few or first iteration application crash. I tried with both QThread and boost threads, but results are same.
void dummyTest(){
for(int i = 0; i < 1000; i++)
setValue(0,rand() % 150);
}
This dummyTest function is also working without problems when called via a button callback, but crash on running on a separate thread.
Here is the code for thread initialization
void startSerialProcessing() {
boost::thread_attributes attr;
attr.set_stack_size(1024);
std::cout << "dummy processor started. \n";
serialThread= new boost::thread(&MavLinkAL::dummyTest, this);
}
My observation is this crash only happens when setValue is called from a separate thread. Here is important lines from coredump file viewed from gdb.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f3f0d6f361f in WTF::StringImpl::~StringImpl() ()
from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#1 0x00007f3f0d6583f8 in JSC::JSValue::toStringSlowCase(JSC::ExecState*) const
() from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#2 0x00007f3f0d68a396 in ?? () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#3 0x00007f3f0d55a9f1 in ?? () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#4 0x00007f3f0d56313f in ?? () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
Any help to solve this problem is really appreciated. Thanks.