本文整理汇总了C++中QThread::wait方法的典型用法代码示例。如果您正苦于以下问题:C++ QThread::wait方法的具体用法?C++ QThread::wait怎么用?C++ QThread::wait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThread
的用法示例。
在下文中一共展示了QThread::wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void WaitThread::run()
{
thread1->wait();
thread2->wait();
qApp->lock();
label->setText("<h1>Done!</h1>");
qApp->unlock();
}
示例2: databaseThreaded
void tst_QDjango::databaseThreaded()
{
if (QDjango::database().databaseName() == QLatin1String(":memory:"))
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QSKIP("Threaded test cannot work with in-memory SQLite database.");
#else
QSKIP("Threaded test cannot work with in-memory SQLite database.", SkipAll);
#endif
QDjangoQuerySet<Author> qs;
QCOMPARE(qs.count(), 0);
QEventLoop loop;
Worker worker;
QThread workerThread;
// fire up worker
worker.moveToThread(&workerThread);
connect(&worker, SIGNAL(done()), &loop, SLOT(quit()));
workerThread.start();
QTimer::singleShot(0, &worker, SLOT(doIt()));
loop.exec();
// check database
QCOMPARE(qs.count(), 1);
// stop thread
workerThread.quit();
workerThread.wait();
}
示例3: debuger_exec
DEBUGER_EXPORT int debuger_exec(int (*fn)(int, char**), void (*exit_fn)()) {
if (fn) {
debuger_thread_runner runner(fn, app_argc, app_argv);
debuger_thread_actor actor;
QThread child;
QObject::connect(&actor, SIGNAL(start()), &runner, SLOT(start()));
QObject::connect(&runner, SIGNAL(finished()), &actor, SLOT(finished()));
runner.moveToThread(&child);
child.start();
actor.start();
int ret = debuger::app->exec();
if (exit_fn)
exit_fn();
// ==== child join
child.quit();
child.wait();
return ret;
}
return debuger::app->exec();
}
示例4: exec
int ServerApp::exec()
{
QThread appThread;
m_impl->application.moveToThread(&appThread);
appThread.start();
m_impl->window.show();
// ... and run
// Qt event loop must be in the main thread
boost::thread orbThread(
boost::bind(&CORBA::ORB::run, m_impl->orb.in()));
int res = m_impl->app.exec();
appThread.quit();
appThread.wait();
m_impl->orb->shutdown(1);
orbThread.join();
delete m_impl;
m_impl = NULL;
return res;
}
示例5: cleanup
void QNetworkConfigurationManagerPrivate::cleanup()
{
QThread* thread = bearerThread;
deleteLater();
if (thread->wait(5000))
delete thread;
}
示例6: main
int main(int argc, char* argv[])
{
#ifdef Q_WS_X11
QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
#endif
QGuiApplication app(argc,argv);
SettingsRef settings;
MainWindow *window;
int result;
app.setOrganizationName("libosmscout");
app.setOrganizationDomain("libosmscout.sf.net");
app.setApplicationName("OSMScout");
settings=new Settings();
//qRegisterMetaType<RenderMapRequest>();
qRegisterMetaType<DatabaseLoadedResponse>();
qmlRegisterType<MapWidget>("net.sf.libosmscout.map", 1, 0, "Map");
qmlRegisterType<Location>("net.sf.libosmscout.map", 1, 0, "Location");
qmlRegisterType<LocationListModel>("net.sf.libosmscout.map", 1, 0, "LocationListModel");
qmlRegisterType<RouteStep>("net.sf.libosmscout.map", 1, 0, "RouteStep");
qmlRegisterType<RoutingListModel>("net.sf.libosmscout.map", 1, 0, "RoutingListModel");
qmlRegisterSingletonType<Theme>("net.sf.libosmscout.map", 1, 0, "Theme", ThemeProvider);
QThread thread;
if (!DBThread::InitializeInstance()) {
std::cerr << "Cannot initialize DBThread" << std::endl;
}
DBThread* dbThread=DBThread::GetInstance();
window=new MainWindow(settings,
dbThread);
window->resize(480,800);
window->setResizeMode(QQuickView::SizeRootObjectToView);
dbThread->connect(&thread, SIGNAL(started()), SLOT(Initialize()));
dbThread->connect(&thread, SIGNAL(finished()), SLOT(Finalize()));
dbThread->moveToThread(&thread);
thread.start();
window->show();
result=app.exec();
delete window;
thread.quit();
thread.wait();
DBThread::FreeInstance();
return result;
}
示例7: moveToThread
void tst_QTimer::moveToThread()
{
QTimer ti1;
QTimer ti2;
ti1.start(MOVETOTHREAD_TIMEOUT);
ti2.start(MOVETOTHREAD_TIMEOUT);
QVERIFY((ti1.timerId() & 0xffffff) != (ti2.timerId() & 0xffffff));
QThread tr;
ti1.moveToThread(&tr);
connect(&ti1,SIGNAL(timeout()), &tr, SLOT(quit()));
tr.start();
QTimer ti3;
ti3.start(MOVETOTHREAD_TIMEOUT);
QVERIFY((ti3.timerId() & 0xffffff) != (ti2.timerId() & 0xffffff));
QVERIFY((ti3.timerId() & 0xffffff) != (ti1.timerId() & 0xffffff));
QTest::qWait(MOVETOTHREAD_WAIT);
QVERIFY(tr.wait());
ti2.stop();
QTimer ti4;
ti4.start(MOVETOTHREAD_TIMEOUT);
ti3.stop();
ti2.start(MOVETOTHREAD_TIMEOUT);
ti3.start(MOVETOTHREAD_TIMEOUT);
QVERIFY((ti4.timerId() & 0xffffff) != (ti2.timerId() & 0xffffff));
QVERIFY((ti3.timerId() & 0xffffff) != (ti2.timerId() & 0xffffff));
QVERIFY((ti3.timerId() & 0xffffff) != (ti1.timerId() & 0xffffff));
}
示例8: main
int main(int argc, char* argv[])
{
#ifdef Q_WS_X11
QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
#endif
QGuiApplication app(argc,argv);
SettingsRef settings;
MainWindow *window;
int result;
app.setOrganizationName("libosmscout");
app.setOrganizationDomain("libosmscout.sf.net");
app.setApplicationName("OSMScout");
settings=std::make_shared<Settings>();
qRegisterMetaType<RenderMapRequest>();
qRegisterMetaType<DatabaseLoadedResponse>();
qRegisterMetaType<osmscout::TileRef>();
qmlRegisterType<MapWidget>("net.sf.libosmscout.map", 1, 0, "Map");
qmlRegisterType<Location>("net.sf.libosmscout.map", 1, 0, "Location");
qmlRegisterType<LocationListModel>("net.sf.libosmscout.map", 1, 0, "LocationListModel");
qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO");
QThread thread;
if (!DBThread::InitializeInstance(/*settings*/)) {
std::cerr << "Cannot initialize DBThread" << std::endl;
}
DBThread* dbThread=DBThread::GetInstance();
window=new MainWindow(settings,
dbThread);
dbThread->connect(&thread, SIGNAL(started()), SLOT(Initialize()));
dbThread->connect(&thread, SIGNAL(finished()), SLOT(Finalize()));
dbThread->moveToThread(&thread);
thread.start();
result=app.exec();
delete window;
QString tmpStylesheet(dbThread->GetStylesheetFilename()+TMP_SUFFIX);
if(QFile::exists(tmpStylesheet)) {
QFile::remove(tmpStylesheet);
}
thread.quit();
thread.wait();
DBThread::FreeInstance();
return result;
}
示例9: waitForProcessingThread
/**
* This prevents deadlock which happens when the processing thread tries to create new MidiSession while the main thread is waiting for it to terminate.
* The cause is that creating MidiSession blocks the processing thread and invokes corresponding slot of Master in its thread as required.
* On the other hand, stop() is usually called in the main thread - the thread of Master. So, we attempt to unblock
* by processing posted QEvent::MetaCall events directed to Master.
*/
void MidiDriver::waitForProcessingThread(QThread &thread, MasterClockNanos timeout) {
while (!thread.wait(timeout / MasterClock::NANOS_PER_MILLISECOND)) {
Master *master = Master::getInstance();
if (QThread::currentThread() == master->thread()) {
QCoreApplication::sendPostedEvents(master, QEvent::MetaCall);
}
}
}
示例10: main
int main(int argc, char* argv[])
{
#ifdef Q_WS_X11
QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
#endif
QGuiApplication app(argc,argv);
SettingsRef settings;
int result;
app.setOrganizationName("libosmscout");
app.setOrganizationDomain("libosmscout.sf.net");
app.setApplicationName("OSMScout");
qRegisterMetaType<RenderMapRequest>();
qRegisterMetaType<DatabaseLoadedResponse>();
qRegisterMetaType<osmscout::TileRef>();
qmlRegisterType<MapWidget>("net.sf.libosmscout.map", 1, 0, "Map");
qmlRegisterType<Location>("net.sf.libosmscout.map", 1, 0, "Location");
qmlRegisterType<LocationListModel>("net.sf.libosmscout.map", 1, 0, "LocationListModel");
qmlRegisterType<RouteStep>("net.sf.libosmscout.map", 1, 0, "RouteStep");
qmlRegisterType<RoutingListModel>("net.sf.libosmscout.map", 1, 0, "RoutingListModel");
qmlRegisterSingletonType<Theme>("net.sf.libosmscout.map", 1, 0, "Theme", ThemeProvider);
osmscout::log.Debug(true);
settings=std::make_shared<Settings>();
QThread thread;
if (!DBThread::InitializeInstance()) {
std::cerr << "Cannot initialize DBThread" << std::endl;
return 1;
}
DBThread* dbThread=DBThread::GetInstance();
dbThread->connect(&thread, SIGNAL(started()), SLOT(Initialize()));
dbThread->connect(&thread, SIGNAL(finished()), SLOT(Finalize()));
dbThread->moveToThread(&thread);
QQmlApplicationEngine window(QUrl("qrc:/qml/main.qml"));
thread.start();
result=app.exec();
thread.quit();
thread.wait();
DBThread::FreeInstance();
return result;
}
示例11: thread
Servatrice_GameServer::~Servatrice_GameServer()
{
for (int i = 0; i < connectionPools.size(); ++i) {
logger->logMessage(QString("Closing pool %1...").arg(i));
QThread *poolThread = connectionPools[i]->thread();
connectionPools[i]->deleteLater(); // pool destructor calls thread()->quit()
poolThread->wait();
}
}
示例12:
AssignmentClient::~AssignmentClient() {
QThread* nodeThread = DependencyManager::get<NodeList>()->thread();
// remove the NodeList from the DependencyManager
DependencyManager::destroy<NodeList>();
// ask the node thread to quit and wait until it is done
nodeThread->quit();
nodeThread->wait();
}
示例13:
ThreadHandle::~ThreadHandle() //停止所有线程,并释放资源
{
QThread * tmp;
for (auto it = threadSize.begin(); it != threadSize.end(); ++it)
{
tmp = it.key();
tmp->exit();
tmp->wait(3000);
delete tmp;
}
}
示例14: cleanupPrivateInstance
// cleans up the settings private instance. Should only be run once at closing down.
void cleanupPrivateInstance() {
// grab the thread before we nuke the instance
QThread* settingsManagerThread = privateInstance->thread();
// tell the private instance to clean itself up on its thread
privateInstance->deleteLater();
privateInstance = NULL;
// quit the settings manager thread and wait on it to make sure it's gone
settingsManagerThread->quit();
settingsManagerThread->wait();
}
示例15: waitForThreadCompletion
int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
{
Q_ASSERT(threadID);
QThread* thread = threadForIdentifier(threadID);
bool res = thread->wait();
clearThreadForIdentifier(threadID);
if (result)
*result = static_cast<ThreadPrivate*>(thread)->getReturnValue();
return !res;
}