I am not finding any way to create thread only once and send request in already running thread because the function which is calling pthread_create needs to be called by below function. Calling of this function can't be handled. This function is called every time whenever a button is clicked from javascript application.
string TemplateJS::InvokeMethod(const string& command) {
// command appears with parameters following after a space
int index = command.find_first_of(" ");
std::string strCommand = command.substr(0, index);
std::string arg = command.substr(index + 1, command.length());
params = arg;
if (strCommand == "request") {
StartThread();
strCommand.append(";");
strCommand.append(command);
return strCommand;
}
return "Unknown C++ method";
}
string TemplateJS::InvokeMethod(const string& command) {
// command appears with parameters following after a space
int index = command.find_first_of(" ");
std::string strCommand = command.substr(0, index);
std::string arg = command.substr(index + 1, command.length());
params = arg;
if (strCommand == "request") {
StartThread();
strCommand.append(";");
strCommand.append(command);
return strCommand;
}
return "Unknown C++ method";
}
To copy to clipboard, switch view to plain text mode
if I call m_signalHandler->doNetworkRequest(); two times in SignalThread then it's working fine and returns good response. But if I call StartThread() two times in above function, app exits.
Added after 10 minutes:

Originally Posted by
d_stranz
I hope this is just a bad cut and paste job, because I have no idea what you intend this line of code to do.
I have changed it to
QCoreApplication app(argc, argv);
To copy to clipboard, switch view to plain text mode
Also according to document since exec() is static function of QCoreApplication so it can be called like: QCoreApplication::exec();
Please correct me if something is wrong. As I am new to this.
Bookmarks