本文整理汇总了C++中QScriptEngine::isEvaluating方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::isEvaluating方法的具体用法?C++ QScriptEngine::isEvaluating怎么用?C++ QScriptEngine::isEvaluating使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::isEvaluating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitFor
bool ScriptJob::waitFor( QObject *sender, const char *signal, WaitForType type )
{
// The called function returned, but asynchronous network requests may have been started.
// Wait for all network requests to finish, because slots in the script may get called
const int finishWaitTime = 100;
int finishWaitCounter = 0;
m_mutex->lockInline();
bool success = m_success;
bool quit = m_quit;
if ( !success || quit ) {
m_mutex->unlockInline();
return true;
}
QScriptEngine *engine = m_engine;
ScriptObjects objects = m_objects;
m_mutex->unlockInline();
while ( finishWaitCounter < 50 && sender ) {
if ( (type == WaitForNetwork && !objects.network->hasRunningRequests()) ||
(type == WaitForScriptFinish && !engine->isEvaluating()) ||
(type == WaitForNothing && finishWaitCounter > 0) )
{
break;
}
QEventLoop loop;
connect( sender, signal, &loop, SLOT(quit()) );
QTimer::singleShot( finishWaitTime, &loop, SLOT(quit()) );
// Store a pointer to the event loop, to be able to quit it from the destructor
m_mutex->lockInline();
m_eventLoop = &loop;
m_mutex->unlockInline();
// Engine continues execution here / waits for a signal
loop.exec();
QMutexLocker locker( m_mutex );
if ( !m_eventLoop || m_quit ) {
// Job was aborted
m_engine = 0;
m_objects.clear();
engine->deleteLater();
return false;
}
m_eventLoop = 0;
++finishWaitCounter;
}
if ( finishWaitCounter >= 50 && type == WaitForScriptFinish ) {
// Script not finished
engine->abortEvaluation();
}
return finishWaitCounter < 50;
}