Beispiel #1
0
void WaitThread::run()
{
    thread1->wait();
    thread2->wait();

    qApp->lock();
    label->setText("<h1>Done!</h1>");
    qApp->unlock();
}
Beispiel #2
0
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();
}
Beispiel #3
0
    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();
    }
Beispiel #4
0
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;
}
void QNetworkConfigurationManagerPrivate::cleanup()
{
    QThread* thread = bearerThread;
    deleteLater();
    if (thread->wait(5000))
        delete thread;
}
Beispiel #6
0
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;
}
Beispiel #7
0
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));
}
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;
}
Beispiel #9
0
/**
 * 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);
		}
	}
}
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;
}
Beispiel #11
0
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();
    }
}
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();
}
ThreadHandle::~ThreadHandle() //停止所有线程,并释放资源
{
    QThread * tmp;
    for (auto it = threadSize.begin(); it != threadSize.end(); ++it)
    {
        tmp = it.key();
        tmp->exit();
        tmp->wait(3000);
        delete tmp;
    }
}
Beispiel #14
0
 // 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();
 }
Beispiel #15
0
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;
}
Beispiel #16
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	Network n;
	QThread inputHandleThread;
	InputHandle ih(&n);
	ih.moveToThread(&inputHandleThread);
	QObject::connect(&inputHandleThread, SIGNAL(started()), &ih, SLOT(start()));
	inputHandleThread.start();

	int ret = a.exec();
	inputHandleThread.quit();
	inputHandleThread.wait();
	return ret;
}
Beispiel #17
0
int main(int argc, char** argv) {
    auto worker = std::make_shared<WorkerThread>();
    auto options = parse_options(argc,argv);
    set_options(*worker,options);

    auto publishers = create_publishers(*worker,options);

    // gui mode
    if (!options.count("novis")){
#ifdef ENABLE_QT5
        qRegisterMetaType<GazeHypsPtr>();
        qRegisterMetaType<std::string>();
        QApplication app(argc, argv);
        GazerGui gui;
        set_options(gui,options);
        WorkerAdapter gazer(worker);
        QThread thread;
        gazer.moveToThread(&thread);

        QObject::connect(&app, SIGNAL(lastWindowClosed()), &gazer, SLOT(stop()));
        QObject::connect(&gazer, SIGNAL(finished()), &thread, SLOT(quit()));
        QObject::connect(&gazer, SIGNAL(imageProcessed(GazeHypsPtr)), &gui,
                         SLOT(displayGazehyps(GazeHypsPtr)), Qt::QueuedConnection);
        QObject::connect(&gazer, SIGNAL(statusmsg(std::string)), &gui, SLOT(setStatusmsg(std::string)));
        QObject::connect(&thread, SIGNAL(started()), &gazer, SLOT(process()));
        QObject::connect(&gui, SIGNAL(horizGazeToleranceChanged(double)), &gazer, SLOT(setHorizGazeTolerance(double)));
        QObject::connect(&gui, SIGNAL(verticalGazeToleranceChanged(double)), &gazer, SLOT(setVerticalGazeTolerance(double)));
        QObject::connect(&gui, SIGNAL(smoothingChanged(bool)), &gazer, SLOT(setSmoothing(bool)));
        if (!options.count("noquit")) {
            QObject::connect(&gazer, SIGNAL(finished()), &app, SLOT(quit()));
        }

        gui.show();
        thread.start();
        auto result = app.exec();
        //process events after event loop terminates allowing unfinished threads to send signals
        while (thread.isRunning()) {
            thread.wait(10);
            QCoreApplication::processEvents();
        }
        return result;
#else
        cerr << "Appplication build without qt. Assuming --novis" << std::endl;
#endif
    }
Beispiel #18
0
void Connection::stopSendQueue() {
    if (auto sendQueue = _sendQueue.release()) {
        // grab the send queue thread so we can wait on it
        QThread* sendQueueThread = sendQueue->thread();
        
        // tell the send queue to stop and be deleted
        
        sendQueue->stop();

        _lastMessageNumber = sendQueue->getCurrentMessageNumber();

        sendQueue->deleteLater();
        
        // wait on the send queue thread so we know the send queue is gone
        sendQueueThread->quit();
        sendQueueThread->wait();
    }
}
Beispiel #19
0
void tst_QPointer::threadSafety()
{

    QThread owner;
    owner.start();

    QThreadPool pool;
    for (int i = 0; i < 300; i++) {
        QPointer<TestRunnable> task = new TestRunnable;
        task->setAutoDelete(true);
        task->moveToThread(&owner);
        pool.start(task);
    }
    pool.waitForDone();

    owner.quit();
    owner.wait();
}
Beispiel #20
0
void Connection::stopSendQueue() {
    if (auto sendQueue = _sendQueue.release()) {
        // grab the send queue thread so we can wait on it
        QThread* sendQueueThread = sendQueue->thread();
        
        // tell the send queue to stop and be deleted
        
        sendQueue->stop();
        sendQueue->deleteLater();
        
        // since we're stopping the send queue we should consider our handshake ACK not receieved
        _hasReceivedHandshakeACK = false;
        
        // wait on the send queue thread so we know the send queue is gone
        sendQueueThread->quit();
        sendQueueThread->wait();
    }
}
Beispiel #21
0
void Faceplus::setEnabled(bool enabled) {
    if (_enabled == enabled) {
        return;
    }
    if ((_enabled = enabled)) {
        _reader = new FaceplusReader();
        QThread* readerThread = new QThread(this);
        _reader->moveToThread(readerThread);
        readerThread->start();
        QMetaObject::invokeMethod(_reader, "init");
        
    } else {
        QThread* readerThread = _reader->thread();
        QMetaObject::invokeMethod(_reader, "shutdown");
        readerThread->wait();
        delete readerThread;
        _active = false;
    }
}
Beispiel #22
0
void AssignmentClient::stopAssignmentClient() {
    qCDebug(assignment_client) << "Forced stop of assignment-client.";

    _requestTimer.stop();
    _statsTimerACM.stop();

    if (_currentAssignment) {
        // grab the thread for the current assignment
        QThread* currentAssignmentThread = _currentAssignment->thread();

        // ask the current assignment to stop
        QMetaObject::invokeMethod(_currentAssignment, "stop");

        auto PROCESS_EVENTS_INTERVAL_MS = 100;
        while (!currentAssignmentThread->wait(PROCESS_EVENTS_INTERVAL_MS)) {
            QCoreApplication::processEvents();
        }
    }
}
Beispiel #23
0
void Agent::aboutToFinish() {
    setIsAvatar(false);// will stop timers for sending billboards and identity packets

    if (_scriptEngine) {
        _scriptEngine->stop();
    }

    // our entity tree is going to go away so tell that to the EntityScriptingInterface
    DependencyManager::get<EntityScriptingInterface>()->setEntityTree(nullptr);

    // cleanup the AssetClient thread
    QThread* assetThread = DependencyManager::get<AssetClient>()->thread();
    DependencyManager::destroy<AssetClient>();
    assetThread->quit();
    assetThread->wait();
    
    // cleanup the AudioInjectorManager (and any still running injectors)
    DependencyManager::destroy<AudioInjectorManager>();
}
Beispiel #24
0
void CmaClient::enterEventLoop(vita_device_t *device)
{
    vita_event_t event;

    qDebug("Starting event loop");

    CmaEvent eventLoop (device);
    QThread thread;
    thread.setObjectName("event_thread");

    eventLoop.moveToThread(&thread);
    connect(&thread, SIGNAL(started()), &eventLoop, SLOT(process()));
    connect(&eventLoop, SIGNAL(refreshDatabase()), this, SIGNAL(refreshDatabase()), Qt::DirectConnection);
    connect(&eventLoop, SIGNAL(finishedEventLoop()), &thread, SLOT(quit()), Qt::DirectConnection);
    thread.start();

    while(isActive()) {
        if(VitaMTP_Read_Event(device, &event) < 0) {
            qWarning("Error reading event from Vita.");
            break;
        }

        // do not create a event for this since there aren't more events to read
        if(event.Code == PTP_EC_VITA_RequestTerminate) {
            qDebug("Terminating event thread");
            break;

            // this one shuold be processed inmediately
        } else if(event.Code == PTP_EC_VITA_RequestCancelTask) {
            eventLoop.vitaEventCancelTask(&event, event.Param1);
            qDebug("Ended event, code: 0x%x, id: %d", event.Code, event.Param1);
            continue;
        }

        // the events are processed synchronously except for cancel/terminate
        qDebug("Sending new event");
        eventLoop.setEvent(event);
    }

    eventLoop.stop();
    thread.wait();
    qDebug("Finishing event loop");
}
Beispiel #25
0
QString RecoveryCurve::uniqueName()
{
    QString retVal;
    QDateTime dateTime = QDateTime::currentDateTime();
    if(typeCurve == Single || typeCurve == SingleOfLumbed)
    {
        retVal = QString("%1-%2-%3-%4-%5-%6-%7.smb").arg(dateTime.date().year()).arg(dateTime.date().month()).arg(dateTime.date().day())
                .arg(dateTime.time().hour()).arg(dateTime.time().minute()).arg(dateTime.time().second()).arg(dateTime.time().msec());
    }
    else
    {
        if(typeCurve == Lumped)
        retVal = QString("Lump_%1-%2-%3-%4-%5-%6-%7.smb").arg(dateTime.date().year()).arg(dateTime.date().month()).arg(dateTime.date().day())
                .arg(dateTime.time().hour()).arg(dateTime.time().minute()).arg(dateTime.time().second()).arg(dateTime.time().msec());
        else
            retVal = QString("LumpClass_%1-%2-%3-%4-%5-%6-%7.smb").arg(dateTime.date().year()).arg(dateTime.date().month()).arg(dateTime.date().day())
                    .arg(dateTime.time().hour()).arg(dateTime.time().minute()).arg(dateTime.time().second()).arg(dateTime.time().msec());
    }

    QThread * currentThread = QThread::currentThread();
    currentThread->wait(1000);
    return retVal;
}
AndroidCamera *AndroidCamera::open(int cameraId)
{
    AndroidCameraPrivate *d = new AndroidCameraPrivate();
    QThread *worker = new QThread;
    worker->start();
    d->moveToThread(worker);
    connect(worker, &QThread::finished, d, &AndroidCameraPrivate::deleteLater);
    bool ok = true;
    QMetaObject::invokeMethod(d, "init", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ok), Q_ARG(int, cameraId));
    if (!ok) {
        worker->quit();
        worker->wait(5000);
        delete d;
        delete worker;
        return 0;
    }

    AndroidCamera *q = new AndroidCamera(d, worker);
    g_cameraMapMutex.lock();
    g_cameraMap->insert(cameraId, q);
    g_cameraMapMutex.unlock();
    return q;
}
Beispiel #27
0
//TODO !!!!!! make it asynchronous. Or do something with it ! That's not right
//in fact now it's blocking.
system_call_wrapper_error_t
CSystemCallWrapper::ssystem_th(const char *command,
                               std::vector<std::string> &lst_output,
                               int &exit_code,
                               bool read_output) {
  CSystemCallThreadWrapper sctw(command, read_output);
  QThread* th = new QThread;
  QObject::connect(&sctw, SIGNAL(finished()), th, SLOT(quit()), Qt::DirectConnection);
  QObject::connect(th, SIGNAL(started()), &sctw, SLOT(do_system_call()));
  QObject::connect(th, SIGNAL(finished()), th, SLOT(deleteLater()));

  sctw.moveToThread(th);
  th->start();
  th->wait();

  QObject::disconnect(&sctw, SIGNAL(finished()), th, SLOT(quit()));
  QObject::disconnect(th, SIGNAL(started()), &sctw, SLOT(do_system_call()));
  QObject::disconnect(th, SIGNAL(finished()), th, SLOT(deleteLater()));

  lst_output = std::vector<std::string>(sctw.lst_output());
  exit_code = sctw.exit_code();
  return sctw.result();
}
void AssignmentClient::stopAssignmentClient() {
    qCDebug(assigmnentclient) << "Forced stop of assignment-client.";

    _requestTimer.stop();
    _statsTimerACM.stop();

    if (_currentAssignment) {
        // grab the thread for the current assignment
        QThread* currentAssignmentThread = _currentAssignment->thread();

        // ask the current assignment to stop
        QMetaObject::invokeMethod(_currentAssignment, "stop", Qt::BlockingQueuedConnection);

        // ask the current assignment to delete itself on its thread
        _currentAssignment->deleteLater();

        // when this thread is destroyed we don't need to run our assignment complete method
        disconnect(currentAssignmentThread, &QThread::destroyed, this, &AssignmentClient::assignmentCompleted);

        // wait on the thread from that assignment - it will be gone once the current assignment deletes
        currentAssignmentThread->quit();
        currentAssignmentThread->wait();
    }
}
Beispiel #29
0
int main(int argc, char *argv[])
{
    QmlProfilerApplication app(argc, argv);

    app.parseArguments();

    if (app.isInteractive()) {
        QThread listenerThread;
        CommandListener listener;
        listener.moveToThread(&listenerThread);
        QObject::connect(&listener, SIGNAL(command(QString)), &app, SLOT(userCommand(QString)));
        QObject::connect(&app, SIGNAL(readyForCommand()), &listener, SLOT(readCommand()));
        listenerThread.start();
        int exitValue = app.exec();
        listenerThread.quit();
        // wait for listener to exit
        listenerThread.wait();
        return exitValue;
    } else {
        int exitValue = app.exec();
        app.outputData();
        return exitValue;
    }
}
	/**
	 * @brief This is a slot function. when a listening thread is terminated,
	 * the thread itself will be deleted here. Some cleanning works is also needed.
	 * @fn zp_net_Engine::on_ListenClosed
	 * @param id the terminated thread id.
	 */
	void zp_net_Engine::on_ListenClosed(QString  id)
	{
		//m_mutex_listen.lock();
		if (m_map_netListenThreads.find(id)!=m_map_netListenThreads.end())
		{
			//Clean objects;
			zp_netListenThread * pListenObj = m_map_netListenThreads[id];
			QThread * pThread = m_map_netInternalListenThreads[id];
			m_map_netListenThreads.remove(id);
			m_map_netInternalListenThreads.remove(id);
			//disconnect signals;
			disconnect(this,&zp_net_Engine::startListen,pListenObj,&zp_netListenThread::startListen);
			disconnect(this,&zp_net_Engine::stopListen,pListenObj,&zp_netListenThread::stopListen);
			disconnect(pListenObj,&zp_netListenThread::evt_Message,this,&zp_net_Engine::evt_Message);
			disconnect(pListenObj,&zp_netListenThread::evt_ListenClosed,this,&zp_net_Engine::on_ListenClosed);
			disconnect(pListenObj,&zp_netListenThread::evt_NewClientArrived,this,&zp_net_Engine::on_New_Arrived_Client);
			pListenObj->deleteLater();
			pThread->quit();
			pThread->wait();
			pThread->deleteLater();

		}
		//m_mutex_listen.unlock();
	}